StringTools
FormatTime
return a string containing a formatted date or time
Calling Sequence
Parameters
Description
Examples
FormatTime( fmt, option )
fmt
-
(optional) string
option
(optional) integer offset or an equation of the form timestamp = integer[4] or of the form offset = integer[4]
The FormatTime(fmt, option) command returns a string containing a formatted date and time. Both the format string fmt and the integer time displacement or equation option are optional. The default format is the ISO 8601 standard default date format, which has the form YYYY-MM-DD, where "Y" denotes a year digit, "M" denotes a digit of the month (01-12), and "D" denotes a digit of the day of the month (01-31). The default time displacement is 0 (the current time).
The time format string is a Maple string that can contain time and date format conversion specifiers, introduced by a % character. This works in a manner similar to the conversion specifiers used in printf or sscanf, but the defined conversion specifiers are different. The format string is copied to the output, but conversion specifiers are replaced with their meanings with respect to the option argument, if present, or the current date and time if no option argument is supplied. A literal % character can be included in the format string by using %%.
The following table lists the known conversion specifiers and their meanings.
%%
the string "%".
%a
abbreviated weekday name.
%A
the full weekday name.
%b
abbreviated month name.
%B
full month name.
%c
a standard date and time representation.
%C
the century number (the year divided by 100 and truncated to an integer in the range 00 - 99).
%d
the two-digit day of the month number (01-31).
%D
the date in the form MM/DD/YY.
%e
the day of the month (1-31).
%H
the hour in a 24-hour clock (00-23).
%I
the hour in a 12-hour clock (01-12).
%j
day number (01 - 366).
%k
the hour in a 24-hour clock ( 0-23).
%l
the hour in a 12-hour clock ( 1-12).
%m
the month number (01 - 12).
%M
the minute after the hour (00-59).
%n
a newline character.
%p
a.m. or p.m.
%r
time representation for a 12-hour clock (using %p).
%R
the same as %H:%M.
%S
seconds after the minute (00 - 61).
%t
a tab character.
%T
same as %H:%M:%S.
%u
weekday as a decimal number (1-7; 1 = Monday).
%U
week number of the year (00 - 53); Sunday is the first day of week 1.
%V
The ISO 8601 week number (01 - 53).
%w
weekday (0-6); 0 = Sunday.
%x
a standard date representation.
%X
a standard time representation.
%y
year within the century (00 - 99).
%Y
year including the century (YYYY).
%Z
time zone name or abbreviation, if available.
Integer offsets passed via the second parameter must be 32-bit integers.
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
The following examples reflect the date on which the help page output was generated.
FormatTime⁡
2024-03-01
FormatTime⁡%Y-%m-%d
FormatTime⁡%Y-%m-%d,0
FormatTime⁡%Y-%m-%d,−60⋅60⋅24
2024-02-29
FormatTime⁡%Y-%m-%d,timestamp=0
1969-12-31
FormatTime⁡%Y-%m-%d,timestamp=iolib⁡25
FormatTime⁡%Y-%m-%d,timestamp=iolib⁡25−60⋅60⋅24
FormatTime⁡%Y-%m-%d,offset=60⋅60⋅24
2024-03-02
seq⁡printf⁡%%%s - %s\n,ch,FormatTime⁡cat⁡%,ch,ch=%aAbBcCdDeHIjklmMprRSTuUVwxXyYZ
%% - % %a - Fri %A - Friday %b - Mar %B - March %c - Fri Mar 01 00:27:22 2024 %C - 20 %d - 01 %D - 03/01/24 %e - 1 %H - 00 %I - 12 %j - 061 %k - 0 %l - 12 %m - 03 %M - 27 %p - AM %r - 12:27:22 AM %R - 00:27 %S - 22 %T - 00:27:22 %u - 5 %U - 08 %V - 09 %w - 5 %x - 03/01/24 %X - 00:27:22 %y - 24 %Y - 2024 %Z - EST
See Also
epoch
FormatMessage
printf
sscanf
string
StringTools[ParseTime]
Download Help Document