Friday, July 25, 2008

Time and date (ISO 8601, RFC 3339, W3C)

Illustration by examples.
(1) ISO 8601
Because the specification also supports rarely-used features, I will not give an exhaustive description. I would like to give some common examples.
(*) Date

Use month and day
YYYY-MM-DD 2008-07-08 MM:01 - 12
DD: 01-31
YYYY-MM 2008-07 Seconds are omitted.
( YYYYMM is not allowed )
YYYY 2008  
YYYYMMDD 20080708 hyphens are omitted
 Use week and day in a week
YYYY-Www-d 2008-W01-1 ww: week number(01-52/53)
d:day in the week(1-7)
YYYY-Www 2008-W01 first week in 2008
YYYYWwwd 2008W011  
YYYYWww 2008W01  
Use day in the year
YYYY-ddd 2008-014 ddd: day in the year
000 - 365(366 in leap years)
YYYYddd 2008123  

(*)Time

hh:mm:ss 16:23:42 hh: hour (00 - 24)
mm:minute(00-59)
ss:second(00-60)
hhmmss 162342 colons are omitted
hh:mm 16:23 seconds are omitted
hhmm 1623  
hh 16 both minutes and seconds are omitted
     
hh:mm:ss.mil 16:23:42.123 More precise

(*)Time zone

hh:mm:ssZ 12:23:43Z 'Z' means the time is measured in UTC.
time+hh:mm 13:23+01:00 The time is hh hours and mm minutes ahead of UTC
time+hhmm 13:23+0100 colon is omitted.
time+hh 13:23+01 The time is hh hours ahead of UTC
time-hh:mm
time-hhmm
time-hh
11:23-01:00
11:23-0100
11:23-01
The time is after UTC. The zone is in west of the zero meridian.

(*) Put together

<date>T<time> 2008-02-12T12:23:34
20080212T122334
2008T1223
<data>T<time>Z 2008-02-12T12:23:34Z
<data>T<time>+<zone> 2008-02-12T13:23:34+01
<data>T<time>-<zone> 2008-02-12T11:23:34-01

Resources:
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
http://en.wikipedia.org/wiki/ISO_8601

(2) RFC 3339
This is a profile of ISO 8601 which defines date and time to be used on internet.
Following is excerpt from the specification:

   date-fullyear   = 4DIGIT
   date-month      = 2DIGIT  ; 01-12
   date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                             ; month/year
   time-hour       = 2DIGIT  ; 00-23
   time-minute     = 2DIGIT  ; 00-59
   time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                             ; rules
   time-secfrac    = "." 1*DIGIT
   time-numoffset  = ("+" / "-") time-hour ":" time-minute
   time-offset     = "Z" / time-numoffset

   partial-time    = time-hour ":" time-minute ":" time-second
                     [time-secfrac]
   full-date       = date-fullyear "-" date-month "-" date-mday
   full-time       = partial-time time-offset

   date-time       = full-date "T" full-time

(3) W3C
W3C also defines a profile of ISO 8601 which can be accessed here.

No comments: