CalendarTime ClassCalendarTime class provides instance variables for elements of
a broken-down clock and calendar UTC time: seconds, minutes, hours,
day of the month, and so on. The methods in this class might be more
convenient in many cases than their functional equivalents in
CTime class.
All of the methods in this class expect that the receiver has made a
previous call to getUTCTime (which is defined in CTime
class). The getUTCTime method fills in the receiver’s value
with the UTC seconds since the epoch. See CTime.
The localTime and gmTime methods contain calls
to the system’s localtime(3) and gmtime(3)
library functions (or localtime_r and gmtime_r). These
manual pages provide more information about how the system
translates seconds since 1900 into a local time zone’s calendar
time, or UTC calendar time.
This brief example prints an ISO-format date and time string.
int main () {
CalendarTime new ct;
ct utcTime;
ct localTime;
printf ("%s\n", ct isoTimeString);
}
secondsminuteshoursdommonthyeardowdoyIntegers that contain the clock time and calendar date
represented by the receiver’s UTC time. The values are translated
using the local time zone information if necessary.
Instance Variable Range
----------------- -----
seconds 0 - 59
minutes 0 - 59
hours 0 - 23
dom (day of the month) 1 - 31
month 0 - 11 (0 = January)
year Years since 1900.
dow (day of the week) 0 - 6 (0 = Sunday)
doy (day of the year) 0 - 365
isdst > 0 : true
0 : false
< 0 : not available
isdstAn Integer value that indicates whether Daylight Savings Time
is in effect on systems that support it. If the value is positive,
Daylight Savings Time is in effect, zero indicates that DST is
not in effect, and a value less than zero indicates that the information
is not available.
timeZoneAn Integer that contains the seconds west of GMT of the
local time zone.
tzStdtzDstgmtOffString objects that contain the abbreviation of the standard
local time zone, the local daylight savings time zone, and the hours
from GMT, usually expressed as a four digit number; e.g., ‘-0700’
for the MST time zone. The value of gmtOff is the result of
dividing the value of the timeZone instance variable by -3600,
them multiplying the result by 100. The haveDst instance variable
is true if the timezone supports daylight savings time, but not
all systems support this. To find out whether daylight savings time
is in effect, the isdst instance variable above, can provide
that information if the machine supports it.
Calling the localTime and zoneInfo methods fill in the
time zone information.
cTimeString (void)Returns a formatted string with the date and time given by the receiver.
The returned String is formatted similarly to the output of the ctime(3) C function, except that the string does not include a trailing newline.
Programs should call the utcTime method to get the current
UTC time, and then either the localTime or gmTime method to
convert the UTC time into calendar day and date information, before
calling this method.
dayName (void)Returns a String with the three-letter abbreviation of
the current day: ‘Sun’, ‘Mon’, ‘Tue’, ‘Wed’,
‘Thu’, ‘Fri’, and ‘Sat’.
gmTime (void)Fills in the receiver’s instance variables with the elements of the UTC calendar time.
Programs should call the utcTime method to get the current
UTC time before calling this method.
isoTimeString (void)Returns a formatted string with the date and time given by the receiver. The returned String has the format of an ISO date and time string.
Programs should call the utcTime method to get the current
UTC time, and then either the localTime or gmTime methods to
convert the UTC time into calendar day and date information, before
calling this method.
localTime (void)Fills in the receiver’s instance variables with the elements of the local calendar time, as determined by the system’s time zone setting.
Programs should call the utcTime method to get the current
UTC time before calling this method.
monName (void)Returns a String with the three-letter abbreviation
of the current time’s month: ‘Jan’, ‘Feb’, ‘Mar’,
‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’,
‘Sep’, ‘Oct’, ‘Nov’, and ‘Dec’.
zoneInfo (void)Fills in the receiver’s timeZone, tzStd, tzDst,
gmtOff, and haveDst with information about the machine’s
current time zone.