0

Example: In mysql db time is: '2014-09-15 14:48:00' this is canada time "America/Toronto" I want to change this time to UTC format. PHP code?

Sanith
  • 613
  • 6
  • 12

4 Answers4

2

Just set input timezone, and output timezone:

$dt = new DateTime('2014-09-15 14:48:00', new DateTimezone('America/Toronto'));
$dt->setTimeZone(new DateTimezone('UTC'));
echo $dt->format('Y-m-d H:i:s');

demo

Glavić
  • 41,315
  • 13
  • 72
  • 105
0

Try this:

date_default_timezone_set('UTC');
echo date('Y-m-d H:i:s');
0

You can change time format using this function date_default_timezone_set('America/Los_Angeles');

Here is list of timezone : http://php.net/manual/en/timezones.php

hardik solanki
  • 2,955
  • 1
  • 16
  • 22
0

Whenever you want to specify the time into a specific time zone or state... Use date_default_timezone_set()...

E.g:

date_default_timezone_set('UTC');
DeDevelopers
  • 571
  • 1
  • 7
  • 25