github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/md/default_time.en.md (about) 1 ### `default_time()` {#fn-defalt-time} 2 3 Function prototype: `fn default_time(key: str, timezone: str = "")` 4 5 Function description: Use an extracted field as the timestamp of the final data 6 7 Function parameters: 8 9 - `key`: key name 10 - `timezone`: Specifies the time zone used by the time text to be formatted, optional parameter, the default is the current system time zone, time zone example `+8/-8/+8:30` 11 12 The pending data supports the following formatting times 13 14 <!-- markdownlint-disable MD038 --> 15 | date format | date format | date format | date format | 16 | ----- | ---- | ---- | ---- | 17 | `2014-04-26 17:24:37.3186369` | `May 8, 2009 5:57:51 PM` | `2012-08-03 18:31:59.257000000` | `oct 7, 1970` | 18 | `2014-04-26 17:24:37.123` | `oct 7, '70` | `2013-04-01 22:43` | `oct. 7, 1970` | 19 | `2013-04-01 22:43:22` | `oct. 7, 70` | `2014-12-16 06:20:00 UTC` | `Mon Jan 2 15:04:05 2006` | 20 | `2014-12-16 06:20:00 GMT` | `Mon Jan 2 15:04:05 MST 2006` | `2014-04-26 05:24:37 PM` | `Mon Jan 02 15:04:05 -0700 2006` | 21 | `2014-04-26 13:13:43 +0800` | `Monday, 02-Jan-06 15:04:05 MST` | `2014-04-26 13:13:43 +0800 +08` | `Mon, 02 Jan 2006 15:04:05 MST` | 22 | `2014-04-26 13:13:44 +09:00` | `Tue, 11 Jul 2017 16:28:13 +0200 (CEST)` | `2012-08-03 18:31:59.257000000 +0000 UTC` | `Mon, 02 Jan 2006 15:04:05 -0700` | 23 | `2015-09-30 18:48:56.35272715 +0000 UTC` | `Thu, 4 Jan 2018 17:53:36 +0000` | `2015-02-18 00:12:00 +0000 GMT` | `Mon 30 Sep 2018 09:09:09 PM UTC` | 24 | `2015-02-18 00:12:00 +0000 UTC` | `Mon Aug 10 15:44:11 UTC+0100 2015` | `2015-02-08 03:02:00 +0300 MSK m=+0.000000001` | `Thu, 4 Jan 2018 17:53:36 +0000` | 25 | `2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001` | `Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)` | `2017-07-19 03:21:51+00:00` | `September 17, 2012 10:09am` | 26 | `2014-04-26` | `September 17, 2012 at 10:09am PST-08` | `2014-04` | `September 17, 2012, 10:10:09` | 27 | `2014` | `2014:3:31` | `2014-05-11 08:20:13,787` | `2014:03:31` | 28 | `3.31.2014` | `2014:4:8 22:05` | `03.31.2014` | `2014:04:08 22:05` | 29 | `08.21.71` | `2014:04:2 03:00:51` | `2014.03` | `2014:4:02 03:00:51` | 30 | `2014.03.30` | `2012:03:19 10:11:59` | `20140601` | `2012:03:19 10:11:59.3186369` | 31 | `20140722105203` | `2014 年 04 月 08 日 ` | `1332151919` | `2006-01-02T15:04:05+0000` | 32 | `1384216367189` | `2009-08-12T22:15:09-07:00` | `1384216367111222` | `2009-08-12T22:15:09` | 33 | `1384216367111222333` | `2009-08-12T22:15:09Z` | 34 <!-- markdownlint-enable --> 35 36 Example JSON extraction: 37 38 ```python 39 # raw json 40 { 41 "time":"06/Jan/2017:16:16:37 +0000", 42 "second":2, 43 "third":"abc", 44 "forth":true 45 } 46 47 # script 48 json(_, time) # extract time field 49 default_time(time) # convert the extracted time field into a timestamp 50 51 # result 52 { 53 "time": 1483719397000000000, 54 } 55 ``` 56 57 Text extraction example: 58 59 ```python 60 # raw log text 61 # 2021-01-11T17:43:51.887+0800 DEBUG io io/io.go:458 post cost 6.87021ms 62 63 # script 64 grok(_, '%{TIMESTAMP_ISO8601:log_time}') # Extract the log time and name the field log_time 65 default_time(log_time) # Convert the extracted log_time field into a timestamp 66 67 # result 68 { 69 "log_time": 1610358231887000000, 70 } 71 72 # For the data collected by logging, it is better to name the time field as time, otherwise the logging collector will fill it with the current time 73 rename("time", log_time) 74 75 # result 76 { 77 "time": 1610358231887000000, 78 } 79 ```