Timestamp for different timezones in php

datetime, php, time, timezone, unix-timestamp

Solution

You can get time zone offset in seconds using `date("Z")`. And then calculate as you need.

date_default_timezone_set('Asia/Calcutta');
echo 'Local time : '.date("r").'<br>'; // local time
echo 'Offset : '.date("Z").'<br>'; // time zone offset from UTC in seconds 
echo 'UTC Time : '.date('r', strtotime(date("r")) + (date("Z")*-1)); echo '<br><br>'; // this is UTC time converted from Local time

date_default_timezone_set('Europe/London');
echo 'Local time : '.date("r").'<br>'; // local time
echo 'Offset : '.date("Z").'<br>'; // time zone offset from UTC in seconds 
echo 'UTC time : '.date('r', strtotime(date("r")) + (date("Z")*-1)); echo '<br><br>'; // this is utc time converted from Local time

Output:

Local time : Tue, 18 Dec 2012 10:53:07 +0530
Offset : 19800
UTC Time : Tue, 18 Dec 2012 05:23:07 +0530

Local time : Tue, 18 Dec 2012 05:23:07 +0000
Offset : 0
UTC time : Tue, 18 Dec 2012 05:23:07 +0000  

Problem

In the below code i need to get unixtimestamp for 2 Country timezone. The output of the code will give me a date with difference but the timestamp is not differ each other. It remains same. Can anyone possible to give a solution to get different timestamp for different timezones? Thanks in advance. ``` date_default_timezone_set('Asia/Calcutta'); echo date("Y-m-d H:i:s")."<br/>"; //2012-12-18 12:12:12 echo strtotime(date("Y-m-d H:i:s",time()))."<br/>"; //1355812934 date_default_timezone_set('Europe/London'); echo date("Y-m-d H:i:s")."<br/>"; //2012-12-18 06:12:12 echo strtotime(date("Y-m-d H:i:s",time()))."<br/>"; //1355812934 ```

Original source