As programmers, we all know we should use ISO 8601 to format date and time when represented numerically.

XKCD 1179

Unfortunately, the POSIX standard does not always provide us with an easy way to use ISO 8601 with strftime. That’s why I’m posting here the right way to do it:

  • date: %Y-%m-%d or %F for recent implementations (example: 2013-12-31)
  • time: %H:%M:%S or %T for recent implementations (example: 23:59:59)