如何获得客户端时区 [英] How to get Client side time zone

查看:145
本文介绍了如何获得客户端时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储客户端(访客)的时区,它将使用我的门户网站。
你能告诉我使用JAVAScript 代码查找客户端机器的时区...

i want to store timezone of client (visitor) which going to use my web portal. would you please show me way to find out timezone for client machine using JAVAScript code...

I need the GMT offset hours like `(GMT +5:30)`.


推荐答案

适用于我的代码...

code that works for me...

<script type="text/javascript" language="javascript" >
    function fnLoad()
    { 
        var objLocalZone = new Date();
        var strLocalZone=''+objLocalZone; 

        var mySplitResult = strLocalZone.split(" ");

        var newLocalZone = mySplitResult[5].slice(0,mySplitResult[5].length-2) +':'+mySplitResult[5].slice(mySplitResult[5].length-2,mySplitResult[5].length);
        document.getElementById("hdnTimeZone").value = newLocalZone;
        //alert('Length : '+newLocalZone);
    }
</script>

隐藏输入

<input type="hidden" id="hdnTimeZone" name="hdnTimeZone"/>

我不知道这是获取客户(访客)时区的正确方法。但它对我来说很好。如果有人有最佳解决方案,请告诉我。谢谢......

i don't know this is proper way to get client(visitor)'s timezone. but it works fine for me.If anybody have optimum solution this let me know. thanks...

这篇关于如何获得客户端时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆