Splunk Search

splunk query to a different timezone fail

cyberpop
Observer

I use fieldformat "Date Time"=strftime('Date Time',"%F %T %:z %Z","Asia/Hong Kong"). but it said the syntax is wrong. how to resolve it, thanks

Labels (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

Wait. What are you trying to do?

As I understand it, you have a field with an epoch-based unix timestamp and want to render it to a string, right?

Splunk renders the time in the timezone set in your user's preferences. Period.

There is no function which lets you render a given timestamp in a different timezone. It's by design and while in some specific use cases it might be less than perfect in most cases it actually saves you a lot of trouble because you always have a fixed timezone against which you can interpret your timestamp strings.

You can cheat a bit by "adjusting" your timestamp by a proper offset between your user's configured timezone and the target timezone and then rendering your timestamp to a string but that's not something I'd recommend since you can quickly lose track the actual time for your events.

0 Karma

cyberpop
Observer

so how to convert to Hong Kong timezone?

0 Karma

cyberpop
Observer

The %HKT didn't work, I use |fieldformat "Date Time"=strftime('DateTime',%F %T %:z %Z %HKT"), it display 2025-09-24 01:31:23 EDT 1KT, I think it is wrong

0 Karma

cyberpop
Observer

 I replace %Z with %HKT as suggested. I use |fieldformat "Date Time"=strftime('DateTime',%F %T %HKT"), it display 2025-09-24 01:31:23 EDT 1KT, I think it take hour (%H) instead of %HKT. I want to get HKT time by using SPL query. kindly help

0 Karma

MuS
SplunkTrust
SplunkTrust

replace %Z with %HKT

0 Karma

MuS
SplunkTrust
SplunkTrust

According to https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations Hong Kong has HKT so you could use %HKT in strftime

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi there,

According to https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/10.0/evaluation-functions/d... strftime only uses a time field and the format like 

strftime(<time>,<format>)

I sugest to remove the ,"Asia/Hong Kong" bit from the SPL.

cheers, MuS

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

 Prepare to elevate your security operations with the powerful upgrade to Splunk Enterprise Security 8.x! This ...

Get Early Access to AI Playbook Authoring: Apply for the Alpha Private Preview ...

Passionate about security automation? Apply now to our AI Playbook Authoring Alpha private preview ...

Reduce and Transform Your Firewall Data with Splunk Data Management

Managing high-volume firewall data has always been a challenge. Noisy events and verbose traffic logs often ...