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..
To get user timezone
<script> alert(Intl.DateTimeFormat().resolvedOptions().timeZone); </script>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.