'PHP time() method not giving timestamp of my timezone
I have a php code which inserts the timestamp in the database for every insert.
I use: time() method to get the time Stamp. but when I send this time Stamp to the mobile client it shows some other time.
How do I get the timestamp for my current time zone, Asia/Calcutta.
Here is my PHP code:
date_default_timezone_set('Asia/Calcutta');
$timeStamp = time();
//insert into notification table
$sql = "insert into notifications (senderUsername,notificationText,timeStamp) values ('$senderUsername','$resultTextValue','$timeStamp')";
This store the value in the DB as 1420829504
This when parsed on my Android client it shows as January 9th 2015, 18:51:44 but I except it as January 10th 2015, 00:21:44
I have already deployed my application on the Play Store, so the only thing I can play with is my server side code.
Solution 1:[1]
You can set your time zone on a per project basis for php like so.
date_default_timezone_set('Asia/Calcutta');
Solution 2:[2]
date_default_timezone_set('Asia/Kolkata');
$time = time();
$actual_time = date('M d Y, 00:H:i',$time);
use $actual_time in you sql database
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | cmorrissey |
| Solution 2 | Randhir Singh |
