Rukmi Patel
Rukmi Patel

Reputation: 2561

change Date format to GMT time

I am having one date

2014-01-23T05:16:45.050Z

I am converting this time in to Y-m-d H:i:s format.

date("Y-m-d H:i:s", strtotime($this->headerStart));

now I want to convert time zone into previous one(2014-01-23T05:16:45.050Z). how to do that?

Upvotes: 0

Views: 101

Answers (2)

Shivam
Shivam

Reputation: 720

Use this it will work.

date("Y-m-d", your timezone) . ."T".date("H:i:s", your timezone)."Z";

Upvotes: 0

Alex Kapustin
Alex Kapustin

Reputation: 2459

function date is already including timezone shift. Timezone information by default situated in php.ini But you can change it by date_default_timezone_set function:

$str = '2014-01-23T05:16:45.050Z';
$parsed = strtotime($str);

echo date("r", $parsed), "\n"; // Thu, 23 Jan 2014 07:16:45 +0200
date_default_timezone_set('America/New_York');
echo date("r", $parsed), "\n"; // Thu, 23 Jan 2014 00:16:45 -0500

Upvotes: 1

Related Questions