This class is used to represent a date/time. The representation may be retrieved from the class either as the constituent parts of a date, or as the number of seconds since a base date, which is 1/1/1600.
The "seconds" viewpoint is always in UTC, whilst the "broken down" viewpoint is always in the local timezone.
The timezone is specified as a timezone object.
If not specified as a parameter the timezone defaults to a value extracted from the system, if possible.
t := Time() # t is uninitialized t.set_current_time(Timezone(-18000)) # t now represents the current time; time zone GMT-5hrs t.parse("1990/12/2 11:22:03 -0500") # the given date t.set_fields(1990, 12, 2, 11, 22, 03, Timezone(-18000)) # the same date t.set_seconds(n, z) # n seconds past the base date in GMT, +/-z mins
Class summary |
Methods inherited from util::Error |
error(a) get_reason() |
Variables inherited from util::Error |
reason |
Methods inherited from lang::Object |
clone(seen) get_class() get_class_name() get_id() hash_code(depth, seen) is_instance(name) |
Variables defined in this class |
hour mday min month ppos psub sec seconds year zone |
Method detail |
The "width" of a field is the number of successive equal pattern chars. For example in the pattern
yyyy/MMM/dd
the widths are 4, 3 and 2 respectively.
The possible pattern chars are :-
E - The weekday. A width < 4 gives the first three chars (eg Mon), otherwise the full day is given (eg Monday)
y - The year. If the width is 2, the year will be the least significant 2 digits (eg "99"), otherwise it is the full year padded to the width.
d - The day of the month padded to the width.
H - The hour in the day using the 24 hour clock padded to the width.
h - The hour in the day using the 12 hour clock padded to the width.
M - The month of the year. If the width is less than 3 then the numeric value is used, padded to the width. If the width is 3, then the abbreviated month is used (eg "Jul"); otherwise the full month is used (eg "July").
m - The minute in the hour padded to the width.
s - The second in the minute padded to the width.
a - am or pm. The width is ignored.
A - AM or PM The width is ignored.
z - the timezone id (eg UTC or +0400). The width is ignored.
Literal strings (which can include the above chars) can be included using single quotes. Two single quotes maps to an actual single quote.
yyyy MM dd HH mm ss -> 1999 12 17 23 30 01 yyyy MM dd HH 'o''clock' mm ss -> 1999 12 17 23 o'clock 30 01 yyyy/M/d HH:mm:ss zzz -> 1999/2/7 23:30:01 PST E MMM dd HH:mm:ss zzz yyyy -> Mon Feb 07 23:30:01 PST 1999 yy MM dd HH mm ss -> 99 12 17 23 30 01
Parse the instance using the given pattern string. The pattern consists of pattern chars and other chars.
The "width" of a field is the number of successive equal pattern chars. For example in the pattern
yyyy/MMM/dd
the widths are 4, 3 and 2 respectively.
Except for the month (see below), the only use of the width is to separate adjacent fields, eg yyyyMMdd with input "19991201".
The possible pattern chars are :-
E - The weekday (eg Mon) - this is just a sequence of upper and lower case chars and is otherwise ignored.
y - The year. If the year is less than 70 it is taken to be 20xx; if it is less than 100 it is taken to be 19xx, otherwise it is as given.
d - The day of the month
H/h - The hour in the day
M - The month of the year. If the width is less than 3 then the numeric value is expected, otherwise the textual value is expected.
m - The minute in the hour
s - The second in the minute
a/A - am or pm. Case is ignored. If pm, then the hour is adjusted accordingly in the result.
z - The timezone (eg UTC or +0400).
Variable detail |