Splunk Search

Convert Zulu time to epoch

Engager

Some Windows events report date/time in zulu format: “‎2013‎-‎03‎-‎27T21:00:32.950000000Z”. I want to convert to epoch. Tried “

eval pt1=strptime(Previous_Time,"%Y-%m-%dT%H:%M:%S.%9NZ")

and some variants. Unfortunately no result. I am obviously overlooking something. Who knows what?

0 Karma

Engager

This solution doesn't appear to account for timezone, which Splunk automatically adjusts for. By adding a % before the Z, Splunk will not perform this adjustment, which unless you have your timezone set as GMT you dont want (this assumes its ACTUALLY zulu time).

Assuming you dont need to do the hyphen replacement, you can also shorthand the format to "%FT%T.%5N%Z"

The solution thus becomes:
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%FT%T.%5N%Z")

or
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9N%Z")

SplunkTrust
SplunkTrust

This works for me:

eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9NZ")

...but only if I type the date in myself. If I copy your date string it fails because the dashes in your date string aren't dashes. Using your copied date string, I need to do this to make it work:

eval time = strptime(replace("2013‎-‎03‎-‎27T21:00:32.950000000Z", "\D", ""), "%Y%m%d%H%M%S%9N")

Engager

This solution doesn't appear to account for timezone, which Splunk automatically adjusts for. By adding a % before the Z, Splunk will not perform this adjustment, which unless you have your timezone set as GMT you dont want (this assumes its ACTUALLY zulu time).

Assuming you dont need to do the hyphen replacement, you can also shorthand the format to "%FT%T.%5N%Z"

The solution thus becomes:
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%FT%T.%5N%Z")

or
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9N%Z")

SplunkTrust
SplunkTrust

I've copied your string into my Notepad++ and it comes out as ?-? for the dashes when trying to interpret them as ANSI, gibberish when trying to interpret them as UTF-8

0 Karma

Engager

Thanks. Never thought strings could be not what they look like. Valuable hint for all coming troubleshoots.

0 Karma