Jul 19, 2016

Standard format for time-stamps in file names based on ISO 8601

Requirements:
We would like a standard that
  • never confuses time zones - a time stamp of which the real time is not known is often worthless
  • lexicographic (aka default) sorting should sort by time
  • close to existing standards
  • legal characters in filenames on Linux, Windows and macOS
  • Bonus: Requires no URL encoding
The closest standard for these requirements is ISO 8601, which requires to use colons, which are not allowed in file names. Therefore there herein proposed standard for time-stamps in file names is ...

Proposed Standard:
  • 1. "Use ISO 8601 and replace colons with underscores"
  • 2. "Prefer UTC, if possible"
  • 3. Adding seconds and/or milliseconds is optional. In fact, everything is simply exactly as described in UTC 8601, except every colon in output strings is replaced with underscores.
Examples:
This yields timestamps in the format "2016-07-19T07_44Z" or "2016-07-19T07_44+01_00".

How To:
Generated in UTC via Linux date command as
date -u "+%Y-%m-%dT%H_%MZ"

Using Java and Yoda time and a format which uses only hours and minutes:
DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mmZ");
DateTime dt = new DateTime();
String text = dt.toString(df);
text = text.replaceAll("_", ":");


References:
That's all.


No comments:

Post a Comment