Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to colon in a time format

Tags:

ISO 8601 recommends the following format for a date and time:

2014-12-29T16:11:20+00:00 

I'm rather fond of this format since it allows for lexical ordering. But there is a small problem: some file systems don't allow colons in file names (at least not normally). ISO 8601 does allow for omitting the colons, but I would rather have some symbol there than have the numbers run together:

2014-12-29T161120+0000 

Does ISO 8601 allow for a symbol other than colons? I couldn't find any indication that it does. If not, is there another well recognized symbol I could use? (Perhaps another standard proposes such a symbol?)

like image 564
jpmc26 Avatar asked Dec 31 '14 19:12

jpmc26


People also ask

What is time format with T and Z?

The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd'T'HH:mm:ss).

Which time format is best?

The ISO 8601 notation is today the commonly recommended format of representing date and time as human-readable strings in new plain-text communication protocols and file formats.


2 Answers

There is none.

ISO 8601 only allows for a colon (:) for separating time components in the extended format:

The basic format is [hh][mm][ss] and the extended format is [hh]:[mm]:[ss].

There is no provision for an alternate extended format.

like image 123
user2864740 Avatar answered Sep 21 '22 19:09

user2864740


For combined date and time representations you must use basic format for both date and time or extended format for both date and time representations to comply with ISO 8601.

Examples of ISO 8601 compliant date and time representations:

2020-12-03T15:05:57+00:00 (extended) 2020-12-03T15:05:57Z (extended) 20201203T150557Z (basic) 

For maximum compatibility with various operating systems file naming requirements and ISO 8601 compliance I think the last example or something similar should work.

Reference: https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations

like image 28
swac Avatar answered Sep 20 '22 19:09

swac