Splunk Search

Convert Zulu time to epoch

landzaat
Explorer

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

Aether
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")

martin_mueller
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")

Aether
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")

martin_mueller
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

landzaat
Explorer

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

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...