-2

I have a datetime in format:

5/20/2011 12:00:00 AM

Even though it is not mentioned in date, I am aware that this date is in CST Timezone (America/Chicago). How do I convert this to UTC time?

I would prefer not to add/subtract time but instead use an existing php function.

Skynet
  • 6,048
  • 5
  • 44
  • 49
kmdhrm
  • 485
  • 6
  • 17

2 Answers2

1

You can use the datetime object for that purpose.

http://php.net/manual/en/datetime.settimezone.php

<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP');

$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP');
mariobgr
  • 2,093
  • 2
  • 13
  • 30
0

You can use this function to set default timezone

date_default_timezone_set


<?php
date_default_timezone_set('UTC'); // To set UTC time


?>
Ekramul Hoque
  • 4,761
  • 3
  • 29
  • 31