Standard date and time notation

The international standard date notation is

  YYYY-MM-DD
Key
   YYYY = the year between 0000 and 9999. 
   MM   = the month between 01 (January) and 12 (December) 
   DD   = the day of the month between 01 and 31.

Values must be padded with leading zeros. For example, the 31st day of January in the year 2012 is written as 2012-01-31

Who should use this and why?

All authors targeting an international audience; particularly on the internet. Ambiguous culture-specific date formats can easily be misinterpreted: formats like 2/4/12 and 4/2/12 are very easily confused. Where the language/culture of the audience is known, then Days or Months written out as text characters may have higher usability, this page deals only with numeric date formats.

Advantages

International Standard ISO 8601

The standard date notation described above is compliant with ISO 8601. Apart from the recommended primary standard notation YYYY-MM-DD, ISO 8601 also specifies a number of alternative formats for use in applications with special requirements.

A week starts with Monday (day 1) and ends with Sunday (day 7).

Week 01 of a year is defined as the first week in the year that contains Thursday.

e.g. Dec-Jan 2015/6: 
  M  T  W  T  F  S  S
 28 29 30 31  1  2  3 = WEEK 53
  4  5  6  7  8  9 10 = WEEK 1

The week number can be described by counting Thursdays: week 12 contains the 12th Thursday of the year.

Time of day

The international standard notation for the time of day is:

hh:mm:ss

key
   hh = Number of complete hours since midnight (00-24)
   mm = Number of complete minutes since the start of the hour (00-59) 
   ss = Number of complete seconds since the start of the minute (00-60).

If the hour value is 24, then the minute and second values must be zero.

The value 60 for ss might sometimes be needed during an inserted leap second. In practice most clocks resynchronize some time after a leap second has happened, to avoid any disruption that an out-of-range timestamp might otherwise cause.

The two notations 00:00 and 24:00 are available to distinguish between midnight at the start of the day and midnight at the end of the day. Where a single representation is required, 00:00 is the preferred notation. Digital clocks display 00:00 and not 24:00.

As with the date notation, the precision can be reduced and/or the separating colons can be omitted, this is often required when creating date stamped files and folders as many file systems do not support the colon character in filenames:
08:59:59
08:59
085959
0859

It is also possible to add fractions of a second after a decimal dot or comma:
14:30:59.5564
143059.5564

If a date and a time are displayed on the same line, always write the date in front of the time. If a date and a time value are stored together in a single data field, then ISO 8601 suggests they be separated by a capital letter T, as in 20120131T143059.

Importantly the standard specifies the use of 24 hour clock system.

Advantages of 24 hour time

Time Zone

By default a date and time as written above is assumed to be in some local time zone. To indicate that a time is measured in Universal Time (UTC), append a capital letter Z:
2012-01-31T08:59Z
08:59:59Z
0859Z

The Z stands for the zero meridian, which goes through Greenwich in London. Universal Time UTC was called Greenwich Mean Time (GMT) before 1972.

For other time zones, the strings below can be added to indicate the offset.
+hh:mm, +hhmm, or +hh
-hh:mm, -hhmm, or -hh

Positive values are hh hours and mm minutes ahead of UTC. (East of meridian)
Negative values are behind UTC (time zones west of the zero meridian)

The following all indicate the same point in time in UTC, CET and EST:
12:00Z
13:00+01:00
0700-0500

When saving date information in a database it is a good idea to save at least two of: Local Time, UTC and Offset. This can simplify any future support for the ever changing world of time zones and daylight saving time changes.

“He was always late on principle, his principle being that punctuality is the thief of time” ~ Oscar Wilde

Related:

bash date command
Windows date command & StampMe script
PowerShell Get-Date & StampMe script & date formats
Dr J R Stockton’s website is full of detailed and accurate advice about date calculations.
Wikipedia ISO 8601 & usage across countries.
www.iso.org - Source for all ISO standards.


© Copyright SS64.com 1999-2013
Some rights reserved