My php web servers timezone is EDT (Eastern Day Light Time (US)). My current timezone is GMT+05.30. I need to enter current timestamp into my mysql database with the timestamp in my current timezone. By the way, I'm using a free php web server for my use. So I will not be having any previleges for modifying the server. Can some one suggest me some way of converting it to my GMT+05.30 from EDT in php using any script.Thanks in advance.
Asked
Active
Viewed 965 times
3 Answers
3
Have a look at the following example
$timezone = new DateTimeZone('Europe/Berlin');
$date = new DateTime('@' . $yourTimestamp, $timezone);
echo $date->format('c');
So through the DateTimeZone Object your Time will be formatted by the DateTime object.

Marcel
- 4,854
- 1
- 14
- 24
-
my time zone is GMT+05.30 so How do I write this code. Can you please explain to me. Sorry I'donot understand what you have mentioned in your answer. Can you please help me. Cause I'm new to php and mysql. – njnjnj Jul 02 '14 at 17:46
-
GMT+5:30 is India Standard Time. So just use 'Asia/Calcutta' instead of 'Europe/Berlin'. You definitely should have a look at http://www.php.net/manual/en/class.datetimezone.php. – Marcel Jul 02 '14 at 17:56
-
Actually, it would be more appropriate to use `'Asia/Kolkata'`. See also [the list on Wikipedia](http://en.wikipedia.org/wiki/List_of_tz_database_time_zones). – Matt Johnson-Pint Jul 03 '14 at 04:45
0
I suggest you use the date_default_timezone PHP function. You can read about it here and here is the list of Supported Timezones
Example:
<?php
date_default_timezone_set('Europe/Amsterdam');
?>

Takoyaro
- 928
- 7
- 14