tencent cloud

Cloud Log Service

Time Value Processing Functions

Download
Focus Mode
Font Size
Last updated: 2026-05-13 19:25:22

Overview

CLS's time processing functions include functions for converting date values to string values, converting time field values to UTC time values and vice versa, and getting the current time.

Function dt_str

Function definition

This function is used to convert a time field value (a date string in a specific format or timestamp) to a target date string of a specified time zone and format.

Syntax description

dt_str(Value, format="Formatted string", zone="")

Parameter description

Parameter
Description
Parameter Type
Required
Default Value
Value Range
data
Field value. For the parsing formats supported, see dateparser.
string
No
-
-
format
Formatted date. For more information, see DateTimeFormatter.
string
No
-
-
zone
Default UTC time, without a specified time zone. For time zone definitions, see ZoneId.
string
No
UTC+00:00
-

Example

Raw log:
{"date":"2014-04-26 13:13:44 +09:00"}
Processing rules:
fields_set("result", dt_str(v("date"), format="yyyy-MM-dd HH:mm:ss", zone="UTC+8"))
Processing result:
{"date":"2014-04-26 13:13:44 +09:00","result":"2014-04-26 12:13:44"}

Function dt_to_timestamp

Function definition

This function is used to convert a time field value (a date string in a specified format; time zone specified) to a UTC timestamp.

Syntax description

dt_to_timestamp(Value, zone="")

Parameter description

Parameter
Description
Parameter Type
Required
Default Value
Value Range
data
Field value. For the parsing formats supported, see dateparser.
string
No
-
-
zone
UTC time is used by default, without a time zone specified. If you specify a time zone, make sure that it corresponds to the time field value. Otherwise, a time zone error occurs. For time zone definitions, see ZoneId.
string
No
UTC+00:00
-

Example

Raw log:
{"date":"2021-10-26 15:48:15"}
Processing rules:
fields_set("result", dt_to_timestamp(v("date"), zone="UTC+8"))
Processing result:
{"date":"2021-10-26 15:48:15","result":"1635234495000"}

Function dt_from_timestamp

Function definition

This function is used to convert a timestamp field value to a time string in the specified time zone.

Syntax description

dt_from_timestamp(Value, zone="")

Parameter description

Parameter
Description
Parameter Type
Required
Default Value
Value Range
data
Field value. For the parsing formats supported, see dateparser.
string
No
-
-
zone
Default UTC time, without a specified time zone. For time zone definitions, see ZoneId.
string
No
UTC+00:00
-

Example

Raw log:
{"date":"1635234495000"}
Processing rules:
fields_set("result", dt_from_timestamp(v("date"), zone="UTC+8"))
Processing result:
{"date":"1635234495000","result":"2021-10-26 15:48:15"}

Function dt_now

Function definition

This function is used to obtain the current datetime of the processing calculation.

Syntax description

dt_now(format="Formatted string", zone="")

Parameter description

Parameter
Description
Parameter Type
Required
Default Value
Value Range
format
Formatted date. For more information, see DateTimeFormatter.
string
No
-
-
zone
Default UTC time, without a specified time zone. For time zone definitions, see ZoneId.
string
No
UTC+00:00
-

Example

Raw log:
{"date":"1635234495000"}
Processing rules:
fields_set("now", dt_now(format="yyyy-MM-dd HH:mm:ss", zone="UTC+8"))
Processing results are for reference only. Specific results are related to the system time:
{"date":"1635234495000","now":"2021-MM-dd HH:mm:ss"}

Function Custom Cls Log Time

Function definition

Customize log time. A new log time will be generated based on your processing rules. Seconds, milliseconds, microseconds, and nanoseconds are supported. After you click Execute Preview, you can view the field value of __TIMESTAMP__ in the processing result to check whether it has been changed to your expected result.

Syntax description

custom_cls_log_time(time)

Parameter description

Parameter
Description
Parameter Type
Required
Default Value
Value Range
time
UTC Timestamp Type. For the definition of time zone, refer to ZoneId. It supports seconds, milliseconds, microseconds, and nanoseconds. For example, 1565064739000.
string
No
-
-

Return value

UTC Timestamp Type. For example, 1565064739000.

Example

Raw log:
{"field1": "1","time":"06/Aug/2019 12:12:19"}
Processing rules:
custom_cls_log_time(dt_to_timestamp(v("time"), zone="UTC+8"))
Processing results are for reference only. Specific results are related to the system time:
{"__TIMESTAMP__":"1565064739000", "field1":"1", "time":"06/Aug/2019 12:12:19"}


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback