Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes between Version 7 and Version 8 of LocaltimeExample

Show
Ignore:
Author:
larsivi (IP: 84.48.50.144)
Timestamp:
05/22/08 16:16:14 (16 years ago)
Comment:

Copied from trunk

Legend:

Unmodified
Added
Removed
Modified
  • LocaltimeExample

    v7 v8  
    11{{{ 
    22#!d 
     3/******************************************************************************* 
     4 
     5        localtime.d 
     6         
     7*******************************************************************************/ 
     8 
    39private import  tango.io.Stdout; 
    410 
    814 
    915        Example code to format a local time in the following format: 
    10         "Wed Dec 31 16:00:00 GMT-0800 1969" 
     16        "Wed Dec 31 16:00:00 GMT-0800 1969". The day and month names 
     17        would typically be extracted from a locale instance, but we 
     18        convert them locally here for the sake of simplicity 
    1119 
    1220******************************************************************************/ 
    1422void main () 
    1523{ 
    16         // set current local time 
    17         auto date = WallClock.toDate; 
     24        /// list of day names 
     25        static char[][] days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; 
     26 
     27        /// list of month names 
     28        static char[][] months = 
     29        [ 
     30            "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
     31            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 
     32        ]; 
     33 
     34        // retreive local time 
     35        auto dt = WallClock.toDate; 
    1836 
    1937        // get GMT difference in minutes 
    20         auto tz = WallClock.zone / Time.TicksPerMinute
     38        auto tz = cast(int) WallClock.zone.minutes
    2139        char sign = '+'; 
    2240        if (tz < 0) 
    2543        // format date 
    2644        Stdout.formatln ("{}, {} {:d2} {:d2}:{:d2}:{:d2} GMT{}{:d2}:{:d2} {}", 
    27                           date.asDay
    28                           date.asMonth
    29                           date.day, 
    30                           date.hour,  
    31                           date.min
    32                           date.sec
     45                          days[dt.date.dow]
     46                          months[dt.date.month-1]
     47                          dt.date.day, 
     48                          dt.time.hours,  
     49                          dt.time.minutes
     50                          dt.time.seconds
    3351                          sign, 
    3452                          tz / 60, 
    3553                          tz % 60, 
    36                           date.year 
     54                          dt.date.year 
    3755                         ); 
    3856}