Splunk Search

how to get current user's timezone in html

arcotdeepika
Engager

Can you help me to get the timezone of current logged in user.

I am able to get the username by below command,
var currentUser =Splunk.util.getConfigValue("USERNAME");

Likewise, any specific command to get users timezone. When i tried with below, it is giving same results for any timezone.

offset = Splunk.util.getServerTimezoneOffset();

Tags (2)
0 Karma

arcotdeepika
Engager

With these, the zone prints entire date.

I need the timezone string to pass to another URL as parmeter.

0 Karma

davebrooking
Contributor

The example in the documentation for getServerTimezoneOffset() is

var serverOffsetSeconds = Splunk.util.getServerTimezoneOffset();

Could it be that you are just missing the var declaration

Dave

0 Karma

arcotdeepika
Engager

No, Even I used 'var' get the same results.

Is there any util function exists to get tz like "username"

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi arcotdeepika,

I haven't seen specific function like Splunk.util.getServerTimezoneOffset().

So can you please try below javascript?

var SearchManager = require("splunkjs/mvc/searchmanager");

var mysearch = new SearchManager({
    id: 'search1',
    app: 'search',
    cache: false,
    search: '| makeresults | eval zone = strftime(now(),"%Z %z")' // changes datetime format as per your requirement.
});

var myResults = mysearch.data("results");
myResults.on("data", function()  {
    var zone = myResults.data().rows[0][0];
    console.log(zone); // You will get zone
});
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...