Asked  7 Months ago    Answers:  5   Viewed   33 times

I need to know what time zone is currently my users are in based on their IP or http header.

I got many answer regarding this issue, but i could not understood those answer. Some said use -new Date().getTimezoneOffset()/60 (from here). But what does it mean?

I have a date_default_timezone_set("Asia/Calcutta"); in the root of my (index.php) page. So for this I have to get the timezone dynamically and set it in place of Asia/Calcutta.



To summarize Matt Johnson's answer in terms of code:

<script type="text/javascript" src="//">
<script type="text/javascript" src="//">
<script type="text/javascript">
    var tz = jstz.determine(); // Determines the time zone of the browser client
    var timezone =; //For e.g.:"Asia/Kolkata" for the Indian Time.
    $.post("url-to-function-that-handles-time-zone", {tz: timezone}, function(data) {
       //Preocess the timezone in the controller function and get
       //the confirmation value here. On success, refresh the page.
Wednesday, March 31, 2021
answered 7 Months ago

To robustly determine a user's timezone using javascript. Check out jsTimezoneDetect.

It will give you an Olsen timezone database key that you can use for server side datetime calculations.

Wednesday, March 31, 2021
answered 7 Months ago

Your problem doesn't involve timezones at all, just the fact that clients can turn their clocks or have their clock skewed considerably. For that the fix is to poll the server every once in a while for an offset fix to use in calculations.

In fact, you don't even need date objects. There is a certain universal instant in time when the auction ends. Let's say it is 1375960662823. Right now, the universal instant in time is 1375960669199, so from that we see that the auction ends in 6 seconds (1375960662823 - 1375960669199 ~ 6000 ). It will end in 6 seconds regardless if I am in Morocco or Japan. Do you understand it yet?

To generate these numbers, on the client side you can call var now = + skewFix where skewFix is the correction that needs to applied in case client has time skew or manually set their computer to wrong time.

In PHP, you can generate it with $now = time() * 1000;

Wednesday, March 31, 2021
answered 7 Months ago

Unfortunately this information is not passed in HTTP headers.

Usually you need cooperating JavaScript to fetch it for you.
Web is full of examples, here is one

Thursday, June 3, 2021
answered 5 Months ago

Just found the problem: PHPExcel translates to UTC time inside: PHPExcel/Shared/Date.php

The function PHPToExcel change temporarily the timezone to UTC, and then go back to the default timezone.

The solution is simple but requires to change that file. Simply copy paste the PHPToExcel function, name it PHPToExcelWithoutUTC (or any name you want) and comment the following lines:

//$saveTimeZone = date_default_timezone_get();


And it works.

EDIT: It seems it's intended to always use UTC time by default. I'm not deleting this thread because it might be useful for those who want the user timezone.

Wednesday, August 18, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :