 |
Changeset 3037
- Timestamp:
- 12/18/07 01:26:13
(1 year ago)
- Author:
- kris
- Message:
asDay() and asMonth() were removed from Date, since they belong in a Locale instead
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3033 |
r3037 |
|
| 12 | 12 | |
|---|
| 13 | 13 | Example code to format a local time in the following format: |
|---|
| 14 | | "Wed Dec 31 16:00:00 GMT-0800 1969" |
|---|
| | 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 |
|---|
| 15 | 17 | |
|---|
| 16 | 18 | ******************************************************************************/ |
|---|
| … | … | |
| 18 | 20 | void main () |
|---|
| 19 | 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 | |
|---|
| 20 | 32 | // retreive local time |
|---|
| 21 | 33 | auto dt = WallClock.toDate; |
|---|
| … | … | |
| 29 | 41 | // format date |
|---|
| 30 | 42 | Stdout.formatln ("{}, {} {:d2} {:d2}:{:d2}:{:d2} GMT{}{:d2}:{:d2} {}", |
|---|
| 31 | | dt.date.asDay, |
|---|
| 32 | | dt.date.asMonth, |
|---|
| | 43 | days[dt.date.dow], |
|---|
| | 44 | months[dt.date.month-1], |
|---|
| 33 | 45 | dt.date.day, |
|---|
| 34 | 46 | dt.time.hours, |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic