Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Notice there is no format in which timezone is specified as 4 digits without the colon, and yet 'date +%z' returns ±NNNN.


Thankfully we have %:z. Relatedly, it’s possible to teach date to do this by default: https://gist.github.com/d081dad407432d53172e30d0d35c39db

  $ date
  2023-08-31T11:15:00-07:00


+%:z is a gnu-specific extension, though. The gist you linked works with gnu libc, but I'm not aware of a POSIX-compliant way to do it.


> timezone is specified as 4 digits without the colon

±NNNN is valid (without colon) if used as part of the "basic" format. i.e. no hyphens or colons anywhere in the format.

Thus the following are equivalent and both valid:

    2023-09-01T09:40:01+08:00
    20230901T094001+0800


Ah, I see that listed as a valid ISO 8601 format in the table, but not in the visualization, so I missed it. Also I can't say I've ever seen the basic format in the wild, is there anywhere it's used regularly?


When the timestamp gets slammed into a file name, as the colon is reserved on Windows and MacOS. Also, when space matters, as it's very slightly shorter.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: