开发者

Calculate flight time

I am working now on a function ot calculate the flight time. I have a very strange problem, because it is a new domain for me.

Here开发者_StackOverflow中文版 is one example:

Outward: 25.02.2011 11:45 Cologne - Las Vegas 26.02.2011 21:18

Return: 18.03.2011 09:49 Las Vegas - Cologne 19.03.2011 11:05

For this flight Kayak is showing Outward: 18:33 hours Return: 17:16 hours

Cologne is GMT +01:00 Las Vegas is America/Los_Angeles timezone -> -08:00

But in the example the flight durariion for the outward flight is calculated with -8 hours offset for Las Vegas and for the return flight with -7 hours offset for Las Vegas. Why?

I have see the timezones here: http://download.geonames.org/export/dump/timeZones.txt

Has anyone any idea?

Thanks Nik


It's because Daylight Savings Time doesn't start on the same date everywhere.

Las Vegas: DST starts on Sunday, 13 March 2011
Cologne: DST starts on Sunday, 27 March 2011

So since your return flight is on the 18th of March, Las Vegas will be in DST, but Cologne won't be.


Ok, I solve the problem. Thanks for the advice to convert both dates to UTC/GMT first.

Here is the trick:

$reset_timezone = date_default_timezone_get();

// convert the first time date_default_timezone_set($timezone_identifier1); $time1 = $date_from.' '.$time_from; $gmtime1 = gmdate('Y-m-d H:i', strtotime($time1));

// convert the second time date_default_timezone_set($timezone_identifier2); $time2 = $date_to.' '.$time_to; $gmtime2 = gmdate('Y-m-d H:i', strtotime($time2));

// reset the timezone again date_default_timezone_set($reset_timezone);

--> here calculate the difference < --

Hope it helps anyone else!

Cheers Nik

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜