132
|
1 /*******************************************************************************
|
|
2
|
|
3 localtime.d
|
|
4
|
|
5 *******************************************************************************/
|
|
6
|
|
7 private import tango.io.Stdout;
|
|
8
|
|
9 private import tango.time.WallClock;
|
|
10
|
|
11 /******************************************************************************
|
|
12
|
|
13 Example code to format a local time in the following format:
|
|
14 "Wed Dec 31 16:00:00 GMT-0800 1969". The day and month names
|
|
15 would typically be extracted from a locale instance, but we
|
|
16 convert them locally here for the sake of simplicity
|
|
17
|
|
18 ******************************************************************************/
|
|
19
|
|
20 void main ()
|
|
21 {
|
|
22 /// list of day names
|
|
23 static char[][] days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
24
|
|
25 /// list of month names
|
|
26 static char[][] months =
|
|
27 [
|
|
28 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
29 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
|
30 ];
|
|
31
|
|
32 // retreive local time
|
|
33 auto dt = WallClock.toDate;
|
|
34
|
|
35 // get GMT difference in minutes
|
|
36 auto tz = cast(int) WallClock.zone.minutes;
|
|
37 char sign = '+';
|
|
38 if (tz < 0)
|
|
39 tz = -tz, sign = '-';
|
|
40
|
|
41 // format date
|
|
42 Stdout.formatln ("{}, {} {:d2} {:d2}:{:d2}:{:d2} GMT{}{:d2}:{:d2} {}",
|
|
43 days[dt.date.dow],
|
|
44 months[dt.date.month-1],
|
|
45 dt.date.day,
|
|
46 dt.time.hours,
|
|
47 dt.time.minutes,
|
|
48 dt.time.seconds,
|
|
49 sign,
|
|
50 tz / 60,
|
|
51 tz % 60,
|
|
52 dt.date.year
|
|
53 );
|
|
54 }
|