Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically detect user's timezone?

Tags:

timezone

php

hi i am creating a web application , where if a user register we will show the created date.

For that we are using Current time stamp in my sql table.Which shows server Time.But we don't know how to convert Time according to user time zone.

Because we are not getting user's country .

Can any on help me to fix it

Thanks in advance :)

like image 956
Balaji Chandrasekaran Avatar asked Mar 05 '11 11:03

Balaji Chandrasekaran


People also ask

How do I automatically detect time zones?

Enabling this feature is easy. Head to Settings > Time & Language > Date & Time and turn on the toggle under Set time zone automatically.

How do I know my client time zone?

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. This offset is changed by dividing by 60 and negating the result.

How do I get user timezone react native?

Pretty much anything you could do in JavaScript on the browser (with exception, of course), you can do in React Native. I would initiate a new date object and call getTimezoneOffset() on it to get the number of minutes the timezone is offset locally.


2 Answers

Use javascript solution

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

Demo should show your timezone in select box.

http://onlineaspect.com/examples/timezone/index.html (Dead link)

like image 153
supersuphot Avatar answered Oct 05 '22 06:10

supersuphot


You can't get a user's timezone on the server side, and you can only make a guess at it on the client side.

If you rely on getting the user's IP address then you could geolocate that and deduce a time.

The way this is usually done is by asking the user (when they register, for instance) what timezone they are in and then use this in your time calculations.

like image 26
cusimar9 Avatar answered Oct 05 '22 04:10

cusimar9