In the past I wrote about a Simple example to show DateTime.Now in ISO 8601 format on ideone.com | Online C# Compiler & Debugging Tool , using ISO 8601 in batch-files, and how ISO 8601 is used in Google Calendar URLs.
Time to write something about ISO 8601 Date, Time and DateTime and Delphi.
First of all the DateUtils unit contains a bunch of routines (for instance DecodeDateWeek) that understand ISO 8601 week numbers, where:
- Weeks start at Monday
- The first week of a year contains (these are equivalent):
- The first thursday in that year
- Has at least 4 days in that year
- Contains the 4th of January
Otherwise the week containing January 1st is week 52 or 53 of the previous year
ISO 8601 also specifies how to format Dates, Times, DateTimes and durations according to some basic principles.
XML uses ISO 8601 to format Date, Time and DateTime and some other formats as text too.
So it is no wonder that since Delphi 6, it contains a XSBuiltIns unit covering (among other things) ISO 8601 formatting.
Given the many Delphi ISO 8601 relates questions on StackOverflow of which I answered two, and my need for ISO 8601 DateTime conversion for exporting Excel XML, here is are some samples to get started in the unit below (and in this codeplex changeset).
The unit covers Date, Time and DateTime.
You can write similar code for Duration.
Oops, I covered it already in ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
Read the rest of this entry »