### A.3 Converting calendar time to character string

The function time2str(tf) converts the calendar time specified by its first argument t, which must be a numeric expression, to a character string (symbolic value). The conversion is controlled by the specified format string f (the second argument), which must be a symbolic expression.

The calendar time passed to time2str has the same meaning as the value returned by the function gmtime (See Obtaining current calendar time). Note that time2str does not correct the specified calendar time for the local timezone, i.e. the calendar time 0 always corresponds to 00:00:00 on January 1, 1970.

For example, the model statements:

param s, symbolic, := time2str(gmtime(), "%FT%TZ");
display s;


may produce the following printout:

s = '2008-12-04T00:23:45Z'


which is a timestamp in the ISO format.

The format string passed to the function time2str consists of conversion specifiers and ordinary characters. Each conversion specifier begins with a ‘%’ character followed by a letter.

The following conversion specifiers may be used in the format string:

%a

The abbreviated (2-character) weekday name.

%A

The full weekday name.

%b

The abbreviated (3-character) month name.

%B

The full month name.

%C

The century of the year, that is the greatest integer not greater than the year divided by 100.

%d

The day of the month as a decimal number (range 01 to 31).

%D

The date using the format %m/%d/%y.

%e

The day of the month like with %d, but padded with blank rather than zero.

%F

The date using the format %Y-%m-%d.

%g

The year corresponding to the ISO week number, but without the century (range 00 to 99). This has the same format and value as %y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead.

%G

The year corresponding to the ISO week number. This has the same format and value as %Y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead.

%h

The same as %b.

%H

The hour as a decimal number, using a 24-hour clock (range 00 to 23).

%I

The hour as a decimal number, using a 12-hour clock (range 01 to 12).

%j

The day of the year as a decimal number (range 001 to 366).

%k

The hour as a decimal number, using a 24-hour clock like %H, but padded with blank rather than zero.

%l

The hour as a decimal number, using a 12-hour clock like %I, but padded with blank rather than zero.

%m

The month as a decimal number (range 01 to 12).

%M

The minute as a decimal number (range 00 to 59).

%p

Either ‘AM’ or ‘PM’, according to the given time value. Midnight is treated as ‘AM’ and noon as ‘PM’.

%P

Either ‘am’ or ‘pm’, according to the given time value. Midnight is treated as ‘am’ and noon as ‘pm’.

%R

The hour and minute in decimal numbers using the format %H:%M.

%S

The second as a decimal number (range 00 to 59).

%T

The time of day in decimal numbers using the format %H:%M:%S.

%u

The day of the week as a decimal number (range 1 to 7), Monday being 1.

%U

The week number of the current year as a decimal number (range 00 to 53), starting with the first Sunday as the first day of the first week. Days preceding the first Sunday in the year are considered to be in week 00.

%V

The ISO week number as a decimal number (range 01 to 53). ISO weeks start with Monday and end with Sunday. Week 01 of a year is the first week which has the majority of its days in that year; this is equivalent to the week containing January 4. Week 01 of a year can contain days from the previous year. The week before week 01 of a year is the last week (52 or 53) of the previous year even if it contains days from the new year. In other word, if 1 January is Monday, Tuesday, Wednesday or Thursday, it is in week 01; if 1 January is Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year.

%w

The day of the week as a decimal number (range 0 to 6), Sunday being 0.

%W

The week number of the current year as a decimal number (range 00 to 53), starting with the first Monday as the first day of the first week. Days preceding the first Monday in the year are considered to be in week 00.

%y

The year without a century as a decimal number (range 00 to 99), that is the year modulo 100.

%Y

The year as a decimal number, using the Gregorian calendar.

%%

A literal ‘%’ character.

All other (ordinary) characters in the format string are simply copied to the resultant string.

The first argument (calendar time) passed to the function time2str must be in the range from –62135596800 to +64092211199 that corresponds to the period from 00:00:00 on January 1, 0001 to 23:59:59 on December 31, 4000 of the Gregorian calendar.