Original Author Paul Laughton, 2011
Page 72
De Re BASIC!
There is a whole family of time format specifiers: %t<x> where <x> is another letter. They operate on an
integer, which they interpret as the number of milliseconds since the beginning of January 1, 1970, UTC
(the "epoch"). You can apply time format specifiers to the output of the TIME() functions. Note,
however, that the %t time specifiers use your local timezone, not the TimeZone.set value.
There are more than 30 time format specifiers. A few examples appear below, but to get the full list you
should read the Android documentation linked above.
PRINT USING$("", "The time is: %tI:%<tM:%<tS %<Tp", time())
% the hard way
PRINT USING$("", "The time is: %tr", time())
% same thing!
02:27:16 PM
example of printed output
t = TIME(2001, 2, 3, 4, 5, 6)
% set 2001/02/03 04:05:06, local timezone
PRINT USING$("sv", "%tA", int(t))
% day in Swedish, prints "lördag"
PRINT USING$("es", "%tB", int(t))
% month in Spanish, prints "febrero"
PRINT USING$("", "%tY/%tm/%td", int(t) , int(t), int(t)) % prints "2001/02/03"
PRINT USING$( , "%tY/%<tm/%<td", int(t))
% prints "2001/02/03"
PRINT USING$("en_GB", "%tH:%<tM:%<tS", int(t))
% prints "04:05:06"
PRINT USING$("in_IN", "%tT", int(t))
% prints "04:05:06"
Note: Date and time are printed for your local timezone, regardless of either the TIMEZONE.SET setting
or the locale parameter. Try the same set of examples with TIMEZONE.SET "UTC". Unless that is your
local timezone, a different hour and perhaps even a different day will be displayed.
Optional Modifiers
The format specifiers can be used exactly as shown in the table. They have default settings that control
how they behave. You can control the settings yourself, fine-tuning the behavior to suit your needs.
You can modify the format specifiers with index, flags, width, and precision, as shown in this example:
"%3$-,15.4f"
"%
3$
-,
15
.
4
f
"
<index> <flags> <width> <precision> <specifier>
Index
Normally the format specifiers are applied to the arguments in order. You can change the order with an
argument index. An index a number followed by a $ character. The argument index 3$ specifies the third
argument in the list.
PRINT USING$("", "%3$s %s %s", "a", "b", "c")
% prints "c a b"
The special argument index "<" lets you reuse an argument.
PRINT USING$("", "%o %<d %<h", int(64) )
% prints "100 64 40"
In the last example, there is only one argument, but three format specifiers. This is not an error because
the argument is reused.