function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sure@DreamSure@Dream 

Getting the site guest user's original timezone

Hi All,

I want to get the site guest user's original timezone.

If we use userinfo.getTimzone(), it will give us the timezone thats being stored in the site guest user record.

What are the possible ways to accomplish this??

Thanks.
Best Answer chosen by Sure@Dream
bob_buzzardbob_buzzard
You'll need to use some JavaScript for this, as you'll be accessing the timezone on the user's device rather than on the server.  The following JavaScript function returns the user's timezone as an IANA zone info key:

https://bitbucket.org/pellepim/jstimezonedetect

All Answers

bob_buzzardbob_buzzard
You'll need to use some JavaScript for this, as you'll be accessing the timezone on the user's device rather than on the server.  The following JavaScript function returns the user's timezone as an IANA zone info key:

https://bitbucket.org/pellepim/jstimezonedetect
This was selected as the best answer
Sure@DreamSure@Dream
Hi Bob,

Thanks for the info.
I will try to use this and let you know.

Thanks.

Sure@DreamSure@Dream
Hi Bob,


I have uploaded the zip file from that site into a static resource, in my developer org.
and have created a sample page like below.
Could you help me with this. Its alerting 1 alone. Is there anythign wrong  with calling the functions?

<apex:page >
    <apex:includeScript value="{!URLFOR($Resource.TimeZone,'/grunt.js')}"/>
    <apex:includeScript value="{!URLFOR($Resource.TimeZone,'/jstz.js')}"/>
    <apex:includeScript value="{!URLFOR($Resource.TimeZone,'/jstz.min.js')}"/>
<script>
    function checkTimeZone()
    {
        alert("1");   
        var x=determine();
       
        alert("2");   
        var y=x.name();
        alert("3");   
         
        alert(y);       
    }  
</script>
<apex:form >
    <apex:commandButton onclick="checkTimeZone();" value="click" rerender="btnID" id="btnID"/>
</apex:form>
</apex:page>

Thanks
CheyneCheyne
Try changing 

var x=determine(); 

to 

var x = jstz.determine();

Also, you don't really need to include all three of those scripts. You should only need to include jstz.min.js. 
Sure@DreamSure@Dream
Hi Cheyne,


Thanks for your reply.
I have tried the same already. But i was not aware that, using one include statement is enough..!!
Sure@DreamSure@Dream
Hi Bob,

I have compared the timezonekeys from this script, with our salesforce timezone keys.
Both are different.
Wont that cause any problem??..!!

Thanks.
bob_buzzardbob_buzzard
I'd expect that to be a problem - I thought Salesforce used IANA too - are the keys completely different, or do you just need to match sections?
Sure@DreamSure@Dream
There are around 100 timezonekeys in salesforce, but in one of the methods in jstz.js file i could see around 70 keys only. So if the user belongs to one of the 30 remaining keys, it will be a problem i guess!!
Victor DeLimaVictor DeLima
There are actually 416 IANA timezones and SFDC only supports 99. If anyone has a conversion table, it would be helpfull.