1

I would like to get the current date-time conveniently on the console in standard ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ

For example: 2019-07-13T01:09:35Z

I know the date command displays the current date-time, but not in ISO 8601 format by default. The -I option shows the date-only portion in standard format. And -Iseconds displays 2019-07-13T01:18:10+00:00. That is close, but:

  • I would prefer the usual Z on the end for an offset of zero, rather than +00:00.
  • I would like something shorter to type, for such a basic common task.

My Question here is the same as this one, but for BSD rather than Linux (apparently).

2

Since you want "Z" (GMT) you can do it simply with a format string and the literal T and Z characters

% TZ=GMT date +"%Y-%m-%dT%H:%M:%SZ"
2019-07-13T02:04:16Z

If you don't want to type that each time, you can make it a function or a script

eg

% isotime()
{
  TZ=GMT date +"%Y-%m-%dT%H:%M:%SZ"
}

% isotime
2019-07-13T02:06:42Z
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.