使用javascript将日期时间转换为不同的时区
我使用Bing API的InstantAnswer源通过jQuery.getJSON以JSON格式检索航class状态信息。 这是我接收的一个例子:
if(typeof SearchCompleted == 'function') SearchCompleted({"SearchResponse":{"Version":"2.2","Query":{"SearchTerms":"LA1442"},"InstantAnswer":{ "Results":[{"ContentType":"FlightStatus","Title":"flight status for Lan Airlines 1442","ClickThroughUrl":"http:\/\/www.bing.com\/search?mkt=en-US&q=LA1442&form=SOAPGN","Url":"http:\/\/www.flightstats.com\/go\/FlightStatus\/flightStatusByFlight.do?id=239598315","InstantAnswerSpecificData":{"FlightStatus":{"AirlineCode":"LA","AirlineName":"Lan Airlines","FlightNumber":"1442","FlightName":"LA1442","FlightHistoryId":239598315,"StatusString":"Landed","StatusCode":76,"OnTimeString":"","ScheduledDeparture":"2011-09-22T17:25:00Z","UpdatedDeparture":"2011-09-22T17:15:00Z","ScheduledArrival":"2011-09-22T18:20:00Z","UpdatedArrival":"2011-09-22T18:17:00Z","OriginAirport":{"Code":"GYE","Name":"Guayaquil","TimeZoneOffset":-18000},"DestinationAirport":{"Code":"UIO","Name":"Quito","TimeZoneOffset":-18000},"DepartureGate":"","DepartureTerminal":"","ArrivalGate":"","ArrivalTerminal":"","PreviousSegment":{"FlightHistoryId":239598314,"OriginAirport":"EZE","DestinationAirport":"GYE"},"DataFreshness":1}}}]}}} /*
与(与时区相关)有问题的信息是这样的:
- 预定出发时间: 2011-09-22T17:25:00Z
- 预定抵达时间: 2011-09-22T18:20:00Z
问题是:如果航class已经离开,我需要预测已经行驶过的飞行路径的百分比。
如果计划出发和预定到达字段与计算机当前时区在同一时区(我只使用客户端脚本),那么这很容易计算 – 但它们不是。 其中一个在厄瓜多尔使用时区(GMT -5),另一个在智利使用时区(GMT -4)。
我的想法是:
- 将两个值都转换为unix时间戳
- 将两个时间戳转换为当前计算机的时区
- 使用这2个时间戳和计算机的当前时间戳计算飞机的行驶百分比
我遇到麻烦的步骤是第2号 – 任何想法? 谢谢!