Sign in Join
Wiki copytemporary

ISO 8601: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: ISO 8601

OldNewLine
1+ISO 8601 is a standard issued by the International Organization for Standardization (ISO) for the date and time. According to ISO 8601, the date is as follows:
2+
3+` YYYY-MM-DD`
4+
5+where YYYY is a year in the Gregorian calendar , MM is a month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31.
6+
7+The time is recorded:
8+
9+` HH:MM:SS`
10+
11+where HH has hours after midnight between 00 and 23. The MM is minutes from the beginning of the previous hour between 00 and 59. The SS is seconds from the beginning of the previous minute between 00 and 59.
12+
13+The combined date and time should be marked with the letter "T":
14+
15+` YYYY-MM-DDTHH:MM:SS`
16+
17+But often the intermediate letter "T" can be replaced by a space.
18+
19+The time zone can be indicated by marking the time difference between the coordinated universal time (UTC) as follows:
20+
21+` YYYY-MM-DDTHH:MM:SS±HH:MM`
22+
23+## Useful functions
24+
25+| Function | Description | Unit |
26+|----|----|----|
27+| DayOfTheMonth | Gives day of month index for a [[TDateTime]] value | DateUtils |
28+| DayOfTheWeek | Gives day of week index for a TDateTime value | DateUtils |
29+| DayOfTheYear | Gives the day of the year for a TDateTime value | DateUtils |
30+| FormatDateTime | Gives a string representation of a TDateTime value with a given format | SysUtils |
31+| WeekOf | Gives the week of the year for a TDateTime value | DateUtils |
32+
33+## Example
34+
35+``` pascal
36+program iso_8601_project;
37+
38+Uses SysUtils,DateUtils;
39+
40+// Combined date and time in UTC e.g // 2018-09-26T12:18:47Z
41+function ISO8601_Combined_date_and_time_in_UTC(a_DateTime: TDateTime; a_Time_zone:string):string;
42+begin
43+ result := FormatDateTime( 'yyyy-mm-dd"T"hh:mm:ss', a_DateTime )+a_Time_zone;
44+end;
45+
46+// Week: e.g. 2018-W39
47+function ISO8601_week(a_DateTime: TDateTime):string;
48+begin
49+ result := FormatDateTime('yyyy', a_DateTime)+'-W' +
50+ (WeekOf( a_DateTime )).ToString ;
51+end;
52+
53+// Date with week number: e.g. 2018-W39-3
54+function ISO8601_Date_with_week_number(a_DateTime: TDateTime):string;
55+begin
56+ result := FormatDateTime('yyyy', a_DateTime)+'-W' +
57+ (WeekOf(a_DateTime)).ToString + '-' + (DayOfTheWeek(a_DateTime)).ToString ;
58+end;
59+
60+// Ordinal date: e.g. 2018-269
61+function ISO8601_Ordinal_date(a_DateTime: TDateTime):string;
62+begin
63+ result := FormatDateTime('yyyy', a_DateTime)+ '-'
64+ + (DayOfTheYear( a_DateTime )).ToString ;
65+end;
66+
67+var
68+ aDateTime: TDateTime;
69+begin
70+ aDateTime := now;
71+ WriteLn('Date: '+ FormatDateTime( 'yyyy-mm-dd', aDateTime )); // 2018-09-26
72+ WriteLn('Combined date and time in UTC: ');
73+ WriteLn(' ' + ISO8601_Combined_date_and_time_in_UTC(aDateTime,'+00:00')); // 2018-09-26T12:18:47+00:00
74+ WriteLn(' ' + FormatDateTime( 'yyyymmdd"T"hhmmss', aDateTime )+'Z'); // 20180926T121847Z
75+ Writeln(' ' + ISO8601_Combined_date_and_time_in_UTC(aDateTime,'Z')); //2018-09-26T12:18:47Z
76+ WriteLn('Week: '+ ISO8601_week(aDateTime) ); // 2018-W39
77+ WriteLn('Date with week number: '+ ISO8601_Date_with_week_number(aDateTime)); // 2018-W39-3
78+ WriteLn('Ordinal date: '+ ISO8601_Ordinal_date(aDateTime)); // 2018-269
79+ ReadLn;
80+end.
81+```
82+
83+---
84+*From the Free Pascal wiki, page "ISO 8601", as it stood on 2019-07-08 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history