Is there a date/time format that does not have spaces?
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?
$ date "+%F-%T"
2010-10-25-16:23:14
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.
I found a simple work around. Simply use underscores for spaces and do a tr
in the CGI script before converting to a date. It looks something like this:
stamp="$(echo $stamp|tr _ ' '|xargs -0 date -d)"
Then use a date that looks something like this:
26_Oct_2010_11:57:56_CDT
which converts to:
date -d "26 Oct 2010 11:57:56 CDT"
精彩评论