How can I get the timezone name in JavaScript?

后端 未结 8 1607
时光取名叫无心
时光取名叫无心 2020-12-12 15:37

I know how to get the timezone offset, but what I need is the ability to detect something like \"America/New York.\" Is that even possible from JavaScript or is that somethi

相关标签:
8条回答
  • 2020-12-12 16:07

    Try this code refer from here

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
    </script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js">
    </script>
    <script type="text/javascript">
      $(document).ready(function(){
        var tz = jstz.determine(); // Determines the time zone of the browser client
        var timezone = tz.name(); //'Asia/Kolhata' for Indian Time.
    
        alert(timezone);
    });
    </script>
    
    0 讨论(0)
  • 2020-12-12 16:11

    Retrieve timezone by name (i.e. "America/New York")

    moment.tz.guess();
    
    0 讨论(0)
提交回复
热议问题