tango.text.convert.DateTime

License:

BSD style: see license.txt

Version:

Jan 2005: initial release Mar 2009: extracted from locale, and converted to a struct

Author:

John Chapman, Kris, mwarning

Support for formatting date/time values, in a locale-specific manner. See DateTimeLocale.format() for a description on how formatting is performed (below).

Reference links:
1
2
http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo(VS.71).aspx
DateTimeLocale DateTimeDefault [public, gshared]
The default DateTimeLocale instance
struct DateTimeLocale
How to format locale-specific date/time output
char[] format(char[] output, Time dateTime, const(char)[] layout)
Format the given Time value into the provided output, using the specified layout. The layout can be a generic variant or a custom one, where generics are indicated via a single character:
                "t" = 7:04
                "T" = 7:04:02 PM
                "d" = 3/30/2009
                "D" = Monday, March 30, 2009
                "f" = Monday, March 30, 2009 7:04 PM
                "F" = Monday, March 30, 2009 7:04:02 PM
                "g" = 3/30/2009 7:04 PM
                "G" = 3/30/2009 7:04:02 PM
                "y"
                "Y" = March, 2009
                "r"
                "R" = Mon, 30 Mar 2009 19:04:02 GMT
                "s" = 2009-03-30T19:04:02
                "u" = 2009-03-30 19:04:02Z
                

For the US locale, these generic layouts are expanded in the following manner:

                "t" = "h:mm"
                "T" = "h:mm:ss tt"
                "d" = "M/d/yyyy"
                "D" = "dddd, MMMM d, yyyy"
                "f" = "dddd, MMMM d, yyyy h:mm tt"
                "F" = "dddd, MMMM d, yyyy h:mm:ss tt"
                "g" = "M/d/yyyy h:mm tt"
                "G" = "M/d/yyyy h:mm:ss tt"
                "y"
                "Y" = "MMMM, yyyy"
                "r"
                "R" = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"
                "s" = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
                "u" = "yyyy'-'MM'-'dd' 'HH':'mm':'ss'Z'"
                

Custom layouts are constructed using a combination of the character codes indicated on the right, above. For example, a layout of "dddd, dd MMM yyyy HH':'mm':'ss zzzz" will emit something like this:
1
Monday, 30 Mar 2009 19:04:02 -08:00

Using these format indicators with Layout (Stdout etc) is straightforward. Formatting integers, for example, is done like so:
1
2
3
Stdout.formatln ("{:u}", 5);
Stdout.formatln ("{:b}", 5);
Stdout.formatln ("{:x}", 5);

Formatting date/time values is similar, where the format indicators are provided after the colon:
1
2
3
Stdout.formatln ("{:t}", Clock.now);
Stdout.formatln ("{:D}", Clock.now);
Stdout.formatln ("{:dddd, dd MMMM yyyy HH:mm}", Clock.now);
T[] formatWide(T)(T[] output, Time dateTime, const(T)[] fmt)
DateTimeLocale* generic() [@property, static]
Return a generic English/US instance
Calendar calendar() [@property]
Return the assigned Calendar instance, using Gregorian as the default
const(char)[] abbreviatedDayName(Calendar.DayOfWeek dayOfWeek)
Return a short day name
const(char)[] dayName(Calendar.DayOfWeek dayOfWeek)
Return a long day name
const(char)[] abbreviatedMonthName(int month)
Return a short month name
const(char)[] monthName(int month)
Return a long month name
DateTimeLocale create() [static]
create and populate an instance via O/S configuration for the current user