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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...