-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.

Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
kmdhrm
  • 505
  • 1
  • 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,143
  • 2
  • 16
  • 31
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,957
  • 3
  • 30
  • 31