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!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...