All Products
Search
Document Center

Resource Orchestration Service:Fn::FormatTime

Last Updated:Mar 15, 2024

The built-in function Fn::FormatTime returns a formatted value of the current time.

Declaration

  • JSON

    • Query the current time of the specified time zone:

      {
        "Fn::FormatTime": [
          format,
          <time_zone>
        ]
      }
    • Query the current time of the default UTC time zone:

      {
       "Fn::FormatTime": format
      }
  • YAML

    • Query the current time of the specified time zone:

      Fn::FormatTime:
        - format
        - <time_zone>
      !FormatTime [format, <time_zone>]
    • Query the current time of the default UTC time zone:

      Fn::FormatTime: format
      !FormatTime format

Parameters

  • format: Required. The parameter value must be a date string, such as "%Y-%m-%d %H:%M:%S".

    The following table describes the fields of the date string.

    Field

    Description

    Example

    %y

    The year without the century part. The year is represented as a zero-padded decimal number. For example, the year 2001 is represented as 01, in which 0 is equivalent to a placeholder.

    21

    %Y

    The year with the century part. The year is represented as a decimal number.

    2021

    %m

    The month represented as a zero-padded decimal number.

    04

    %d

    The day in a month. The day is represented as a zero-padded decimal number.

    07

    %H

    The hour represented as a zero-padded decimal number based on the 24-hour clock.

    14

    %I

    The hour represented as a zero-padded decimal number based on the 12-hour clock.

    08

    %M

    The minute represented as a zero-padded decimal number.

    09

    %S

    The second represented as a zero-padded decimal number.

    10

    %a

    The abbreviated name of the day of a week.

    Wed

    %A

    The full name of the day of a week.

    Wednesday

    %b

    The abbreviated name of a month.

    Apr

    %B

    The full name of a month.

    April

    %c

    The date and time.

    Wed Apr 7 08:15:10 2021

    %j

    The day in a year. The day is represented as a zero-padded decimal number.

    097

    %p

    Valid values:

    • AM: morning

    • PM: afternoon

    AM

    %U

    The sequence number of the week in a year. The sequence number is represented as a zero-padded decimal number. Sunday is the first day in a week.

    Note

    All days before the first Sunday of a new year are included in Week 0.

    14

    %w

    The day in a week. The day is represented as a decimal number.

    0 specifies Sunday, and 6 specifies Saturday.

    3

    %W

    The sequence number of the week in a year. The sequence number is represented as a decimal number. Monday is the first day in a week.

    Note

    All 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 represented as a zero-padded decimal number.

    091798

    %z

    The UTC offset, in the format of +HHMM or -HHMM.

    +0000

    %%

    The percent sign (%).

    %

  • time_zone: the time zone, such as UTC(default), Asia/Shanghai.

Return value

The formatted value of the current time.

Examples

  • Fn::FormatTime: %Y-%m-%d %H:%M:%S

    In this example, the following result is returned:

    2021-06-11 03:48:19
  • Fn::FormatTime: %Y-%m-%d %H:%M:%S,Asia/Shanghai

    In this example, the following result is returned:

    2021-06-11 12:01:25