Conversion Between Datetime Objects and Datetime Strings
- Processing functions
- Intelligent conversion function: dt_parse, which converts a datetime string or Unix timestamp to a datetime object.
- dt_astimezone function, which returns a datetime object with new time zone information.
- Scenario 1: Convert a datetime string without time zone information to a datetime object in a specified time zone.
For example, the datetime string 2019-06-02 18:41:26 without time zone information can be converted between different time zones based on the Unix timestamp. Convert the datetime in the Los Angeles time zone to the datetime in the Shanghai time zone.
- Raw log: The value of the time field is Los Angeles time.
{ "time" : "2019-06-04 2:41:26" } - Processing rule
e_set("timestamp", dt_parsetimestamp(v("time"), tz="America/Los_Angeles")) e_set("Shanghai_time", dt_parse(v("timestamp"), tz="Asia/Shanghai")) - Processing result
{ "Shanghai_time": "2019-06-04 17:41:26+08:00", "time": "2019-06-04 2:41:26", "timestamp": 1559641286 }
- Raw log: The value of the time field is Los Angeles time.
- Scenario 2: Convert a datetime string without a time zone to a datetime object with a time zone
- Raw log
{ "time" : "2019-07-10 06:58:19" } - Processing rule
e_set("new_time", dt_parse(v("time"), tz="Asia/Shanghai")) - Processing result
{ "new_time": "2019-07-10 06:58:19+08:00", "time": "2019-07-10 06:58:19" }
- Raw log
- Scenario 3: Convert a datetime string with time zone information to a datetime object in the target time zone.
- Raw log
{ "time" : "2019-06-04 2:41:26+08:00" } - Processing rule
e_set("new_time",dt_astimezone(v("time"), "America/Los_Angeles")) - Processing result
{ "new_time": "2019-06-03 11:41:26-07:00", "time": "2019-06-04 2:41:26+08:00" }
- Raw log
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot