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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...