|
Revision 768, 1.2 kB
(checked in by kris, 2 years ago)
|
presentation on linux was missing a newline
|
| Line | |
|---|
| 1 |
/******************************************************************************* |
|---|
| 2 |
|
|---|
| 3 |
@file localtime.d |
|---|
| 4 |
|
|---|
| 5 |
*******************************************************************************/ |
|---|
| 6 |
|
|---|
| 7 |
private import mango.io.Print; |
|---|
| 8 |
|
|---|
| 9 |
private import mango.sys.Epoch; |
|---|
| 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" |
|---|
| 15 |
|
|---|
| 16 |
******************************************************************************/ |
|---|
| 17 |
|
|---|
| 18 |
void main () |
|---|
| 19 |
{ |
|---|
| 20 |
Epoch.Fields fields; |
|---|
| 21 |
|
|---|
| 22 |
// get current time and convert to local |
|---|
| 23 |
fields.setLocalTime (Epoch.utcMilli); |
|---|
| 24 |
|
|---|
| 25 |
// get GMT difference |
|---|
| 26 |
int tz = Epoch.tzMinutes; |
|---|
| 27 |
char sign = '+'; |
|---|
| 28 |
if (tz < 0) |
|---|
| 29 |
tz = -tz, sign = '-'; |
|---|
| 30 |
|
|---|
| 31 |
// format fields |
|---|
| 32 |
Println ("%.3s %.3s %02d %02d:%02d:%02d GMT%c%02d%02d %d", |
|---|
| 33 |
fields.toDowName, |
|---|
| 34 |
fields.toMonthName, |
|---|
| 35 |
fields.day, |
|---|
| 36 |
fields.hour, |
|---|
| 37 |
fields.min, |
|---|
| 38 |
fields.sec, |
|---|
| 39 |
sign, |
|---|
| 40 |
tz / 60, |
|---|
| 41 |
tz % 60, |
|---|
| 42 |
fields.year |
|---|
| 43 |
); |
|---|
| 44 |
} |
|---|