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
  • 681
  • 7
  • 13

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ć
  • 42,781
  • 13
  • 77
  • 107
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
  • 3,153
  • 1
  • 17
  • 28
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
  • 581
  • 1
  • 7
  • 25