Is there a date/time format that does not have spaces?

Viewed 17033

I have a CGI script that will convert a given string to a date/time using the unix date command. I'm looking for a format that can easily be embedded to a URL without the need for escaping with a %20. The client that is building the date/time into the URL does not have a conversion to unix time (seconds since epoch) and does not have a way to convert to the offset from zulu (ISO8601 will not work). However, it is possible to reformat the date/time used to build the URL in many other ways.

Are there any other options to build a datetime in a non-spaced format?

3 Answers

The ISO 8601 format is perfect for this and is built-in to date.

Here are some examples at the various levels of supported precision:

$ date --iso-8601
2021-06-26
$ date --iso-8601=minutes
2021-06-26T16:01-0600
$ date --iso-8601=seconds
2021-06-26T16:01:23-0600
$ date --iso-8601=ns
2021-06-26T16:03:19,903115256-0600

See man date for more options.

Related