Reputation:
I have time in this format and I want to convert this into UTC
timezone.
: "2015-03-17T07:46:52+0100"
: "yyyy-MM-dd'T'HH:mm:ssZ"
I am using Codeigniter framework.
Upvotes: 1
Views: 7490
Reputation: 1226
Try the getTimezone and setTimezone, see the example
(But this does use a Class)
UPDATE:
Without any classes you could try something like this:
$the_date = strtotime("2015-03-17T07:46:52+0100");
echo(date_default_timezone_get() . "<br />");
echo(date("Y-d-mTG:i:sz",$the_date) . "<br />");
echo(date_default_timezone_set("UTC") . "<br />");
echo(date("Y-d-mTG:i:sz", $the_date) . "<br />");
Upvotes: 2
Reputation: 212402
Pretty straightforward using DateTime objects
$string = "2015-03-17T07:46:52+0100";
$dt = new DateTime($string);
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->format('Y-m-d H:i:s');
Upvotes: 7