Jaimin
Jaimin

Reputation: 811

timezone conversion in php

My defaulst timezone in google calendar is (GMT-08:00) Pacific Time. Now i generate a meeting request and invite two persons.
1) one person whose default timezone in his calendar is (GMT+05:30) Pacific Time and his email are coming through microsoft exchange server.
2) second i invite a person on gmail account who is having default timezone as (GMT+05:30).
the ics file which i view has DTSTART as DTSTART:20110506T170000Z it just means like
yyyymmdd T hhmmss so here time comes proper in gmail.
but the first person viewing microsoft gets DTSTART:20110506T070000Z so here my question is how to convert timezone so that both comes the same...

date_default_timezone_set($timezonename[0]->timzone_val); 
$meetingstamp = strtotime($meeting_date." ".$timezonename[0]->timzone_val);
$dtstart= gmdate("Ymd\This\Z",$meetingstamp);
$dtend= gmdate("Ymd\This\Z",$meetingstamp+$meeting_duration);
$todaystamp = gmdate("Ymd\This\Z");

here my timzone comes as America/Los_Angeles so how which function shall i use to get proper timings...????

Upvotes: 1

Views: 5298

Answers (1)

Stefan Gehrig
Stefan Gehrig

Reputation: 83622

$start = new DateTime($meeting_date, new DateTimeZone($timezonename[0]->timzone_val);
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', $meeting_duration));

echo $start->format('Ymd\THis\Z');
echo $end->format('Ymd\THis\Z');

It should be an upper-case H in the date formatting string by the way, beacuse lower-case h represents ours in 12-hout-format.

EDIT after last comment

$start = new DateTime('2011-05-07 10:00', new DateTimeZone('PDT'));
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', 1*60*60));

echo $start->format('Ymd\THis\Z');
echo "\n";
echo $end->format('Ymd\THis\Z');

results in

20110507T170000Z
20110507T180000Z

That are exactly the values you'd like to get.

Upvotes: 3

Related Questions