Fn::FormatTime returns the current time in a specified format.
Declaration
-
JSON
-
Get the current time in a specified time zone:
{ "Fn::FormatTime": [ format, <time_zone> ] } -
Get the current time in the default UTC time zone:
{ "Fn::FormatTime": format }
-
-
YAML
-
Get the current time in a specified time zone:
Fn::FormatTime: - format - <time_zone>!FormatTime [format, <time_zone>] -
Get the current time in the default UTC time zone:
Fn::FormatTime: format!FormatTime format
-
Parameters
-
format: Required. A date format string, such as"%Y-%m-%d %H:%M:%S".The following table describes the supported format fields.
Field
Description
Example
%y
The year without the century part, as a zero-padded decimal number. For example, 2001 is represented as 01.
21
%Y
The year with the century part, as a decimal number.
2021
%m
The month, as a zero-padded decimal number.
04
%d
The day of the month, as a zero-padded decimal number.
07
%H
The hour (24-hour clock), as a zero-padded decimal number.
14
%I
The hour (12-hour clock), as a zero-padded decimal number.
08
%M
The minute, as a zero-padded decimal number.
09
%S
The second, as a zero-padded decimal number.
10
%a
The abbreviated weekday name.
Wed
%A
The full weekday name.
Wednesday
%b
The abbreviated month name.
Apr
%B
The full month name.
April
%c
The date and time.
Wed Apr 7 08:15:10 2021
%j
The day of the year, as a zero-padded decimal number.
097
%p
Valid values:
-
AM: morning
-
PM: afternoon
AM
%U
The week number of the year (Sunday as the first day of the week), as a zero-padded decimal number.
NoteAll days before the first Sunday of a new year are included in Week 0.
14
%w
The weekday as a decimal number.
0 represents Sunday and 6 represents Saturday.
3
%W
The week number of the year (Monday as the first day of the week), as a decimal number.
NoteAll days before the first Monday of a new year are included in Week 0.
14
%x
The date.
04/07/21
%X
The time.
08:15:10
%Z
The name of the time zone. Valid values:
-
UTC
-
GMT
UTC
%f
The microsecond, as a zero-padded decimal number.
091798
%z
The UTC offset, in the format of
+HHMMor-HHMM.+0000
%%
The percent sign (%).
%
-
-
time_zone: Optional. The time zone, such asUTC(default), Asia/Shanghai.
Return value
The current time in the specified format.
Examples
Fn::FormatTime: %Y-%m-%d %H:%M:%SSample result:
2021-06-11 03:48:19Fn::FormatTime: %Y-%m-%d %H:%M:%S,Asia/ShanghaiSample result:
2021-06-11 12:01:25