Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user timezone using jquery?

I would like to get their timezone with names like 'Asia/Calcutta' or 'Australia/Darwin'

I have php installed on myserver and its time set to 'UTC'

like image 563
user967144 Avatar asked Nov 11 '11 06:11

user967144


People also ask

How do I find user timezone?

The client's timezone offset could be detected by using the Date object's getTimezoneOffset() method. The getTimezoneOffset() method returns the time difference between UTC time and local time, that is the time offset, in minutes.

What is user time zone?

The user time zone is a client-specific time zone that can be defined for the user time and user date of each individual user in the user master record. It is contained in the system field sy-zonlo.

How do I use getTimezoneOffset?

getTimezoneOffset() method is used to return the time difference between Universal Coordinated Time (UTC) and local time, in minutes. If your time zone is GMT+5, -300 (60*5) minutes will be returned. Daylight savings prevent this value from being constant. Parameter: This method does not accept any parameter.


1 Answers

For detecting timezone offset you can use this function:

function get_time_zone_offset( ) {
  var current_date = new Date();
  return parseInt(-current_date.getTimezoneOffset() / 60);
}

Example you can see here

like image 151
ValeriiVasin Avatar answered Sep 19 '22 00:09

ValeriiVasin