Converting a Timestamp into a Date
Function Name
$timestamp_format(String A, String B)
Parameter Description
- String A: timestamp to be converted. The value is a numeric string containing a maximum of 20 digits. You can also use the built-in function $timestamp() to obtain the current timestamp.
- String B: date and time value, consisting of the year, month, day, hour, minute, second, and millisecond. Where,
- Year: represented by letter "y" and consists of 4 characters.
- Month: represented by letter "M" and consists of 1 to 2 characters.
- Day: represented by letter "d" and consists of 1 to 2 characters.
- Hour: represented by letter "H" and consists of 0 to 2 characters.
- Minute: represented by letter "m" and consists of 0 to 2 characters.
- Second: represented by letter "s" and consists of 0 to 2 characters.
- Millisecond: represented by letter "S" and consists of 3 characters.
- Each letter has its own meaning and is case sensitive.
- If one of "H", "m", "s" is 0, the other two must also be 0.
In a date and time value, spaces, hyphens (-), slashes (/), and colons (:) are optional. For example, the formats include but are not limited to the following:
- yyyy-MM-dd HH:mm:ss
- yyyyMMddHHmmss
- yyyyMMddHHmmssSSS
- yyyy-M-d H:m:s
- MM-dd-yyyy HH:mm:ss
- MM/dd/yyyy HH/mm/ss
- MM/d/yyyy H/mm/ss
- MM/d/yyyy H/mm/ss SSS
- yyyyMMdd SSS
Function Description
Converts a timestamp into a date in the corresponding format. The timestamp is the total number of milliseconds from 1970-01-01 00:00:00 to the specified time.
Parameter A in the function supports the following types:
- Date and time in the format listed in Parameter Description
- Environment parameters
- Local parameters
- Other built-in functions
Parameter B in the function supports the following types:
- Date and time in the format listed in Parameter Description
- Environment parameters
- Local parameters
- Other built-in functions
Application Scenarios
The timestamp-to-date function can be used in the following scenarios for API automation:
- Request URL
- Request header
- Request body
- Checkpoint property
- if condition
- for loop interrupt condition
Example
- Request URL
As shown in the following figure, the value of date in the request URL is the timestamp-to-date conversion function. Parameter A in the function is the built-in function $timestamp() for obtaining the current timestamp. For details, see Obtaining the Current Timestamp. Parameter B is yyyy-MM-dd HH:mm:ss.
- Request header
As shown in the following figure, the value of date in the request header is the timestamp-to-date conversion function. Parameter A in the function is the environment parameter date, and parameter B is yyyyMMddHHmmss. For details about how to set environment parameters, see Setting Environment Parameters.
- Request body
As shown in the following figure, the request body uses the timestamp-to-date conversion function. Parameter A in the function is 123456789, and parameter B is yyyyMMddHHmmssSSS.
- Checkpoint property
As shown in the following figure, the target value of the checkpoint property result is the timestamp-to-date function. Parameter A in the function is the built-in function $timestamp() for obtaining the current timestamp, and parameter B is MM/dd/yyyy HH/mm/ss.
- if condition
As shown in the following figure, the target value of the if condition is the timestamp-to-date function. Parameter A in the function is the built-in function $timestamp() for obtaining the current timestamp, and parameter B is MM/d/yyyy H/mm/ss SSS.
- for loop interrupt condition
As shown in the following figure, the target value of the for loop interrupt condition is the timestamp-to-date function. Parameter A in the function is the built-in function $timestamp() for obtaining the current timestamp, and parameter B is yyyyMMdd SSS.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.