Author: Hotrod
Summary: Parsing and conversion of various time formats
Keywords: time
Categories: demo
Time Parsing
This is a demo pipe that provides examples of dealing with timestamps in various formats, performing format conversion, as well as time zone conversion.
See the time action for documentation.
Pipe Definition
name: library-time
input:
echo:
json: true
ignore-linebreaks: false
event: |
{
"input_iso" : "2022-08-03T16:46:41.619Z",
"input_epoch": 1659544878,
"input_epoch_ms": 1659545181941,
"input_datetime": "2022-02-22 14:18:23"
}
actions:
# Add a timestamp (ISO 8601 timestamp)
- time:
output-field: output_ts_iso_default
# Add a timestamp ISO 8601 timestamp with explicit time zone and format
- time:
output-field: output_ts_iso_explicit
output-timezone: UTC
output-format: default_iso
# Parse UNIX/epoch timestamp, output as ISO
- time:
input-field: input_epoch
input-format: epoch_secs
output-field: output_parsed_unix
output-format: default_iso
# Parse UNIX/epoch-like timestamp with milliseconds (common in javascript), output as ISO
- time:
input-field: input_epoch_ms
input-format: epoch_msecs
output-field: output_parsed_unix_ms
output-format: default_iso
# Parse ISO, output to UNIX/epoch
- time:
input-field: input_iso
input-format: default_iso
output-field: output_parsed_iso
output-format: epoch_secs
# Parse datetime string with no timezone, output ISO.
# This assumes the input is in UTC
- time:
input-field: input_datetime
input-format: "%Y-%m-%d %H:%M:%S"
output-field: output_parsed_datetime
# Parse datetime string with no timezone, specify input timezone, output ISO.
- time:
input-field: input_datetime
input-timezone: "Antarctica/Vostok"
input-format: "%Y-%m-%d %H:%M:%S"
output-field: output_parsed_datetime_tz
output:
print: STDOUT