time
Formats the current time using
POSIX strftime
tokens.
Summary
- [time locale] Time format string [/time]
| Parameter
|
Description
|
Default
|
| locale |
Format the time according to the named locale. |
None |
| adjust |
Temporarily adjust the time for display purposes. |
None |
| gmt |
Display time as GMT. |
No
|
| hours |
Force the adjust parameter value to be treated as a number of hours. |
No
|
| sortable |
Returns the date in %Y%m%d format. |
No
|
| tz |
Use the passed timezone to display the time. |
None |
| zerofix |
Strips leading zeroes from numbers. |
No
|
| interpolate |
Parse Interchange tags, included in the body text, before this container tag executes. |
No
|
| reparse |
Process any Interchange tags found in the text output from this tag. |
Yes
|
Examples
Tag expansion example
All examples on this page assume that today is Monday 01 January 2001.
The year is [time]%Y[/time].
|
|
The year is 2001.
|
Perl example
$Tag->time({
locale => $locale,
body => $format,
});
|
or similarly with positional parameters:
|
$Tag->time($locale, $attribute_hash_reference, $format);
|
Description
Formats the current time using
POSIX strftime
tokens.
For example:
[time]%A %d %B %Y[/time]
|
|
Monday 01 January 2001
|
See the time format tokens section, below,
and/or the
strftime(3)
UNIX manual page, for information on the recognised tokens.
The tokens are the same as modern UNIX date(1) command
arguments.
The tag body defaults to %c, if it is empty.
Time format tokens
Time format tokens are introduced by a "%" character and
terminated by a conversion specifier character, as listed in the following
table:
| Token
|
Description
|
| %a |
The abbreviated weekday name according to the current locale. |
| %A |
The full weekday name according to the current locale. |
| %b |
The abbreviated month name according to the current locale. |
| %B |
The full month name according to the current locale. |
| %c |
The preferred date and time representation for the current locale. |
| %C |
The century number (year/100) as a 2-digit integer.
(SU) |
| %d |
The day of the month as a decimal number (range 01 to 31). |
| %D |
Equivalent to "%m/%d/%y".
(Yecch -- for North Americans only).
Americans should note that "%d/%m/%y" is rather common in other countries, and actually makes more sense.
In an international context, the %D format is ambiguous and should therefore not be used.
(SU) |
| %e |
Like "%d", the day of the month as a decimal number, but a leading zero is replaced by a space.
(SU) |
| %E |
Modifier:
use alternative format, see below.
(SU) |
| %F |
Equivalent to "%Y-%m-%d" (the ISO 8601 date format).
(C99) |
| %G |
The ISO 8601 year with century as a decimal number.
The 4-digit year corresponding to the ISO week number (see "%V").
This has the same format and value as "%y", except that if the ISO week number belongs to the previous or next year, that year is used instead.
(TZ) |
| %g |
Like "%G", but without century.
I.e., with a 2-digit year (00-99).
(TZ) |
| %h |
Equivalent to "%b".
(SU) |
| %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 (24-hour clock) as a decimal number (range 0 to 23);
single digits are preceded by a blank.
(See also "%H".) (TZ) |
| %l |
The hour (12-hour clock) as a decimal number (range 1 to 12);
single digits are preceded by a blank.
(See also "%I".) (TZ) |
| %m |
The month as a decimal number (range 01 to 12). |
| %M |
The minute as a decimal number (range 00 to 59). |
| %n |
A newline character.
(SU) |
| %O |
Modifier:
use alternative format, see below.
(SU) |
| %p |
Either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale.
Noon is treated as "pm" and midnight as `am'. |
| %P |
Like "%p" but in lowercase:
"am" or "pm" or a corresponding string for the current locale.
(GNU) |
| %r |
The time in "AM" or "PM" notation.
In the POSIX locale this is equivalent to "%I:%M:%S %p".
(SU) |
| %R |
The time in 24-hour notation (%H:%M).
(SU) For a version including the seconds, see "%T", below. |
| %s |
The number of seconds since the Epoch (1970-01-01 00:00:00 UTC).
(TZ) |
| %S |
The second as a decimal number (range 00 to 60).
The range is up to 60 to allow for occasional leap seconds. |
| %t |
A tab character.
(SU) |
| %T |
The time in 24-hour notation (%H:%M:%S).
(SU) |
| %u |
The day of the week as a decimal, range 1 to 7, Monday being 1.
See also "%w".
(SU) |
| %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 week 01.
See also "%V" and "%W". |
| %V |
The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
See also "%U" and "%W".
(SU) |
| %w |
The day of the week as a decimal, range 0 to 6, Sunday being 0.
See also "%u". |
| %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 week 01. |
| %x |
The preferred date representation for the current locale without the time. |
| %X |
The preferred time representation for the current locale without the date. |
| %y |
The year as a decimal number without a century (range 00 to 99). |
| %Y |
The year as a decimal number including the century. |
| %z |
The time-zone as hour offset from GMT.
Required to emit RFC 822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z").
(GNU) |
| %Z |
The time zone or name or abbreviation. |
| %% |
A literal "%" character. |
Some time format tokens can be modified by preceding the conversion
specifier character by the "E" or "O" modifier to indicate
that an alternative format should be used.
If the alternative format or token does not exist for the current locale,
the behaviour will be as if the unmodified conversion specification were used.
SU, the Single Unix Specification, mentions
%Ec, %EC, %Ex, %EX, %Ey,
%EY, %Od, %Oe, %OH, %OI,
%Om, %OM, %OS, %Ou, %OU,
%OV, %Ow, %OW and %Oy,
where the effect of the "O" modifier is to use alternative numeric
symbols (roman numerals, for instance), and that of the "E" modifier
is to use a locale-dependent alternative representation.
Parameters
locale
Format the time according to the named locale,
assuming that locale is available on your operating system.
For example, the following:
1. [time locale=en_US]%d %B %Y[/time]
2. [time locale=fr_FR]%d %B %Y[/time]
|
1. 01 January 2001
2. 01 janvier 2001
|
adjust
If you wish to temporarily adjust the time for display purposes,
you can pass an adjust parameter with the number of hours (plus or minus).
1. [time]%a %d %b %Y %H:%M:%S[/time]
2. [time adjust="-3"]%a %d %b %Y %H:%M:%S[/time]
|
1. Mon 01 Jan 2001 11:29:03
2. Mon 01 Jan 2001 08:29:03
|
If the number ends in zero and has 3 digits or more,
it is assumed that the number is in timezone format (i.e +500)
the local time or from GMT:
1. [time]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time adjust="-330"]%a %d %b %Y %H:%M:%S %Z[/time]
3. [time adjust="-300"]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 2001 11:29:03 EST
2. Mon 01 Jan 2001 07:59:03 EST
3. Mon 01 Jan 2001 08:29:03 EST
|
If you want to force the number to be just a number of hours then
add the "hours" parameter:
1. [time]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time adjust="100" hours=1]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 2001 11:29:03 EST
2. Fri 05 Jan 2001 15:29:03 EST
|
If adjust is an Interchange time duration with a suffix of
sec, min, hrs, days, or weeks, then that will be used:
1. [time]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time adjust="2 days"]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 2001 11:29:03 EST
2. Wed 03 Jan 2001 11:29:03 EST
|
|
Note
The timezone will not be changed in line with the selected time adjustment.
You should either use a format that doesn't display the timezone,
use the "tz" parameter or display the timezone string
yourself.
|
Global Interchange timezone setup
You can adjust time globally for an Interchange installation by
setting the TZ environment variable.
On many systems,
this can be done as follows:
$ export TZ=Europe/London
$ /path/to/bin/interchange --restart
|
% setenv TZ Europe/London
% /path/to/bin/interchange --restart
|
On most modern UNIX systems,
the above will cause all dates and times to be adjusted and displayed
using the PST timezone.
gmt
If you want to display time as GMT/UTC then use this parameter,
as follows:
1. [time]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time gmt=1]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 2001 11:33:26 EST
2. Mon 01 Jan 2001 16:33:26 EST
|
|
Note
Although the time itself will be correct,
the timezone will not be set to GMT/UTC.
You should use the "tz" parameter if
you want to set the timezone.
|
hours
Forces the adjust parameter value to be treated as a number of hours.
For example:
1. [time]%a %d %b %Y %H:%M:%S[/time]
2. [time adjust="100" hours=1]%a %d %b %Y %H:%M:%S[/time]
|
1. Mon Jan 01 2001 11:29:03
2. Fri Jan 05 2001 15:29:03
|
sortable
Overrides the tag body with %Y%m%d so that a sortable date value
will be generated.
tz
Use the passed timezone to display the time.
Will adjust for hours difference.
For example:
1. [time tz=GMT0BST]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time tz=CST6CDT]%a %d %b %Y %H:%M:%S %Z[/time]
3. [time tz=PST8PDT]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 04:43:02 GMT
2. Mon 31 Dec 22:43:02 CST
3. Mon 31 Dec 20:43:02 PST
|
The first alphabetical string,
in the timezone specification,
is the timezone name when not in
daylight savings time,
the digit is the number of hours displacement from GMT/UTC and the second
alphabetical string is the timezone name when in daylight savings time.
On modern UNIX-based systems,
you can also pass POSIX timezone names as follows:
1. [time tz="Europe/London"]%a %d %b %Y %H:%M:%S %Z[/time]
2. [time tz="America/Chicago"]%a %d %b %Y %H:%M:%S %Z[/time]
3. [time tz="America/Los_Angeles"]%a %d %b %Y %H:%M:%S %Z[/time]
|
1. Mon 01 Jan 04:43:02 GMT
2. Mon 31 Dec 22:43:02 CST
3. Mon 31 Dec 20:43:02 PST
|
The POSIX timezone names are considered to be easier to understand
and more accurate than the older timezone specifications,
described above.
|
Note
The "tz" parameter may not work at all on non-UNIX and
non-POSIX operating systems.
If this is a problem then upgrade to a decent operating system.
|
zerofix
Strips leading zeros from numbers
[time zerofix=1]%d %B %Y %H:%M[/time]
|
|
1 January 2001 4:43
|