Ramya
Ramya

Reputation: 1

How to get the browser timezone and country name?

How to get the browser timezone (client's timezone) and country name when the client logins into the application in different countries in jQuery/JavaScript?

I tried many codes from google but I am getting server time instead of client's timezone. Please help me to get out of this..

Upvotes: 0

Views: 1938

Answers (2)

Dayachand Patel
Dayachand Patel

Reputation: 497

You can get timezone by using moment.js and jstz.js

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.6/jstz.min.js"></script>

and after including both js

<script>
 $(function(){
   var currentTimezone = jstz.determine();
   var timezone = currentTimezone.name();
   alert(timezone);
});

</script>

Upvotes: 0

Mani
Mani

Reputation: 2655

To get user timezone

<script>
	alert(Intl.DateTimeFormat().resolvedOptions().timeZone);
</script>

Upvotes: 3

Related Questions