Get the Date/Time in ISO 8601 Format on the CLI
The GNU date
command on Linux makes it easy to generate the current timestamp in the ISO 8601 format, suitable for plugging into, say, HTML metadata, or an Eleventy template. But I keep forgetting the command-line options!
date -Is
(That’s a capital I
telling it to use ISO-8601, and a lower-case s
telling it to include the current time down to the nearest second.)
Result: 2023-10-08T17:04:29-07:00
Update: Hank G. points out that the command on macOS is also simple, but the options are slightly different. On a Mac you have to type:
date -Iseconds
Update 2: I’ve confirmed that, as expected, FreeBSD uses the same syntax as macOS. Or vice versa, I suppose!