ISO 8601
|
ISO 8601 is an international standard for date and time representations. Its full English title is Data elements and interchange formats -- Information interchange -- Representation of dates and times. The current version is the third edition, ISO 8601:2004, dated 2004-12-03. This replaces the ISO 8601:1988 first edition and the ISO 8601:2000 second edition.
The basic concept for the standard is to establish a moment in time as precisely or generally as the user chooses through a string of characters. The characters are ordered from the largest representations (years) to the smallest (seconds, or fractions thereof.) After establishing this moment, the standard also allows for intervals and recurring intervals.
Contents |
Dates
Dates can be described in three different ways in ISO 8601: Calendar dates, ordinal dates, and week dates. Each is detailed below.
There is an important note on years however. Year 0001 corresponds to AD 1. The year before that is 0000, which corresponds to 1 BC. The year before that is -0001, which corresponds to 2 BC. This pattern continues. This system had already been used by astronomers (see astronomical year numbering) and may clarify the dispute about when a new century begins (see 20th century).
The standard uses the Gregorian calendar. Dates in other calendars such as the Julian calendar should in theory be converted to the Gregorian calendar before representation in ISO 8601. However, in practice, this may or may not happen, and the standard recognizes this fact by suggesting that, in cases where there may be confusion, it is imperative that the sender and receiver must both agree which calendar is to be used. When the Gregorian calendar is applied to dates prior to its adoption, it is known as the Proleptic Gregorian calendar.
Years must be written with at least four digits to be unambiguous. Years written with two digits preceded by a hyphen may represent a year in an implied century, and two digits alone are used to designate a century. Unfortunately, common practice is to use two digits for either a year in an implied modern century or in the first century (89 might be 89 or 1989.) To prevent confusion, four digits are strongly recommended, as 0089 or 1989. Years with three digits such as 879 must be written with a leading zero, as 0879. Years may be described by more than four characters by agreement of sender and receiver. This addresses the year 10,000 problem, allowing the standard to specify dates later than AD 10000 or earlier than 10001 BC.
For purposes of reference ISO 8601 assigns the number 1875 to the year in which the Convention du Mètre was signed in Paris.
With the exception of years (as noted above), whenever a specification includes multiple characters, all the characters must be filled. This means that if hh is specified and the current hour is 4, the result must include a leading 0, as 04.
Calendar dates
Calendar dates are dates as most people know them. They involve determining the day within a year by counting within a month. For example, April 5 is a calendar date. ISO 8601 specifies calendar dates like this: YYYY-MM-DD. This means, for example, that the fifth day of the fourth month of 1981, or 1981-04-05, is written 1981-04-05. It may also be written 19810405 if compactness is more important than readability by human beings. The format with separators is called the extended format, while the format without is called the basic format.
The standard allows for dates to be written with less precision. For example, you may write 1981-04 to mean April, 1981 (this is, in fact, the basic version -- you should not leave out the separator.) You may simply write 1981 to refer to that year. Or you may even write 19 to refer to a century.
The standard also allows for dates which include an implied element, such as an implied century. It is careful to emphasize the importance of clear communication between sender and receiver when implied elements are being used. It is a lack of such clarity that led to the year 2000 problem.
Ordinal dates
Ordinal dates are dates in which a day is determined by counting within the entire year. Thus a day is represented by three digits, starting with January 1 being 001, February 1 being 032, and so on. December 31 will therefore be 365, except in leap years, where it will be 366.
An ordinal date is specified with YYYY-DDD. Thus, 1981-04-05 is represented as 1981-095. The basic format of this drops the separator, becoming 1981095.
Week dates
Week dates are dates in which a day is determined by counting within a week. Weeks are given two digits beginning with 01 as the first week of the year (see below), up to 52 or 53 being the last week of the year. By convention, the week starts with Monday. Each day is given one digit beginning with 1 as Monday leading to 7 as Sunday. The extended format representation of week dates is YYYY-Www-d, where W is the actual letter W, ww refers to the two digit week number, and d is the day's number. This means that 1981-04-05, the Sunday of the 14th week in 1981, is represented as 1981-W14-7, or 1981W147. This format can also specify a week, as 1981W14.
The first week of a year is the first week which includes at least four days in the new year (again using the convention that Monday is the first day of the week). It follows that the first week of the year is always the week which includes the first Thursday of January, and also the week which includes January 4. This means that week 01 may include days from the previous year, or that week 52 or 53 may include days from the next year. For example, 2004-01-01 occurs on a Thursday. This means that 2004-W01 consists of Monday, 2003-12-29 through Sunday, 2004-01-04. 2005-01-01 occurs on a Saturday, meaning that 2004-W53 is 2004-12-27 through 2005-01-02, and 2005-W01 starts on 2005-01-03.
For a good mathematical treatment of the ISO 8601 Calendar see the external link The Mathematics of the ISO 8601 Calendar below.
Times
ISO 8601 uses the 24-hour clock system that is used by much of the world. The basic format is hhmmss and the extended format is hh:mm:ss. hh refers to an hour between 00 and 24. mm refers to a minute between 00 and 59. ss refers to a second between 00 and 60. Using 60 to represent the second is only used when a leap second is being added. So a time might appear as 13:47:30, or 134730.
It is also acceptable to omit elements to reduce precision. hh:mm, hhmm, and hh are all used.
Fractions may also be used with all three of the time elements. These are indicated by using the decimal point (either a comma or dot). A fraction may only refer to the most precise component of a time representation -- that is, if you are indicated 14 hours, 30 and one half minutes, you do not include a seconds figure. You represent it as 14:30.5 or 1430.5. (You may replace the "." with a "," depending on the local custom.)
Midnight is a special case and can be referred to as both 00:00 and 24:00. In practice it is preferred to use 00:00, but when indicating the end of a day use 24:00. 24:00 on 1981-04-05 is the same as 00:00 on 1981-04-06.
Time zones
If no time zone information is given with a time, the time zone intended is ambiguous. While it may be safely assumed to be in local time when used between two people in the same area, it is easily confusing when used to communicate between two different areas of the world. So it is often preferable to include the time zone information with the time.
UTC
If the time is in UTC, it is very easy to show this. Simply add a Z directly after the time, without a space. 09:30 UTC is therefore represented as 09:30Z or 0930Z. 14:45:15 UTC would be 14:45:15Z or 144515Z.
Other time zones
Other time zones are specified by their offset from UTC, in the format ±hh:mm, ±hhmm, or ±hh. So if the time being described is one hour later than UTC (such as the time in Berlin during the winter) the offset would be +01:00, +0100, or simply +01. This is appended to the time in the same way that Z was above. Note that the offset is the actual offset from UTC, and doesn't include any information on daylight saving time. Times expressed in local time for a user in Chicago would be -06:00 for the winter (Central Standard Time) and -05:00 for the summer (Central Daylight Time). The following times all refer to the same moment: 18:30Z, 22:30+04, 1130-0700, and 15:00-03:30. (It could also be expressed using a fraction of the hour, as 18.5Z.)
Combined representations
Combining date and time representations is quite simple. It is in the format of <date>T<time>. The <date> and <time> sections are any proper representation of the date and time created by following the standard. A common use could be YYYY-MM-DDThh:mm:ss±hh:mm. 1981-04-05T14:30:30-05:00, for example.
The standard allows to replace the T with a space if no misunderstanding arises. This is commonly done for human communications. Above interval then looks like 1981-04-05 14:30:30-05:00.
Time intervals
Time intervals specify an amount of time. They may be specified in four ways:
- Start and end, such as 2002-03-01T13:00:00Z/2003-05-11T15:30:00Z
- Start and duration, such as 2002-03-01T13:00:00Z/P1Y2M10DT2H30M
- Duration and end, such as P1Y2M10DT2H30M/2003-05-11T15:30:00Z
- Duration only, such as P1Y2M10DT2H30M
See below for explanations of the items beginning with P.
Of these, the first three require two separate values, separated by the interval designator, which is usually a forward slash (/). (The double hyphen (--) is permissible in some applications but is not preferred.) An example using the format from item #1 is 1981-04-05T14:30:30-05:00/2004-07-14T15:30:30-05:00. If any elements are missing from the second value, they are assumed to be the same as the first value, including time zone elements.
Durations
Durations are represented by the format PnYnMnDTnHnMnS (you may replace nM with nW to use the week format.) In this representation replace n with the appropriate number for the element that follows it (leading zeros are optional but may clarify ambiguous durations) The capital letters (P, Y, M, W, D, T, H, M, and S) are used as they are and not replaced. Thus P3Y6M4DT12H30M0S defines a period of three years, six months, four days, twelve hours, thirty minutes, and zero seconds. Elements may be omitted if their value is zero.
Alternately, a format more similar to the combined representation may be used: PYYYY-MM-DDThh:mm:ss. To represent the same interval as above in this format, use P0003-06-04T12:30:00.
Repeating intervals
Repeating intervals are formed by adding Rn/ to the beginning of an interval expression, where R is used as the letter itself and n is replaced by the number of repetitions. Leaving out the value for n means an unbounded number of repetitions. So, to repeat the interval of P1Y2M10DT2H30M five times starting at 2002-03-01T13:00:00Z, use R5/2002-03-01T13:00:00Z/P1Y2M10DT2H30M.
Uses
On the Internet, ISO 8601 is used by the W3C, defining a profile of the standard that restricts the supported formats to reduce the chance of error and the complexity of software. See also W3C link in External links, below.
External links
- The ISO 8601 Date Format (http://www.hermetic.ch/cal_stud/formats.htm)
- ISO 8601 summary by Markus Kuhn (http://www.cl.cam.ac.uk/~mgk25/iso-time.html)
- International Date Format Campaign (http://www.saqqara.demon.co.uk/datefmt.htm)
- ISO 8601 Implementation Around The World (http://www.qsl.net/g1smd/isoimp.htm)
- ISO 8601 discussion group at Yahoo! (http://groups.yahoo.com/group/iso8601/)
- ISO 8601 section of Open Directory Project (http://dmoz.org/Science/Reference/Standards/Individual_Standards/ISO_8601/)
- Note about Date and Time Formats by W3C (http://www.w3.org/TR/NOTE-datetime)
- RFC 3339, Date and Time on the Internet, 2002-July
- Purchase the ISO 8601:2004 standard (http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=40874) (English, 33 pages, PDF, CHF 122)
- ISO 8601 draft copies in PDF format (http://dmoz.org/Bookmarks/G/g1smd/Links_to_PDF_Copies_of_ISO_8601_Standard/)
- Current date in week date and ordinal date format (http://www.personal.ecu.edu/mccartyr/isowdcal.html)
- The Mathematics of the ISO 8601 Calendar (http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm)de:ISO 8601
eo:ISO 8601 fi:ISO 8601 fr:ISO 8601 ja:ISO 8601 nl:ISO 8601 pl:ISO 8601 sl:ISO 8601 sv:ISO 8601 zh:ISO 8601