Wednesday, October 6, 2021

“date -d” vs. “date -s”

Rachel Kroll:

$ date -d @1700000000
Tue Nov 14 14:13:20 PST 2023

The problem is, there’s another command very much like it that will even spit out the same output, only it has a nice little side-effect: it also sets the clock. That command is date -s.

If you’re on a QWERTY layout or are generally familiar with it, you might notice that [S] and [D] are right next to each other and are an easy typo to make with your left hand. That’s one way to screw up.

Another problem is that you might not have known that -s has that effect[…]

There doesn’t seem to be a -s in the Mac version of date.


Update (2021-10-08): Matt Garber:

That’s one of several differences between the GNU coreutils date on Linux, and the BSD version included in at least FreeBSD and macOS. Also, the BSD version’s -d flag is completely different: “Set the kernel’s value for daylight saving time”.

Simon Stiefel:

On macOS, no option is needed to change the flag which is arguably worse, e.g. date 1234 sets the time.

Chris Dzombak:

also, crontab -e vs. crontab -r

2 Comments RSS · Twitter

On macOS, this is 'date - r ' to convert a timestamp to human readable date.

If you install `coreutils` on macos then you should end up with `gdate` which works as described.

Leave a Comment