开发者

Right way to convert dates to UTC

my apologies if this question doesn't make much sense, but I'm new(ish) to Actionscript, and was wondering if you could help me solving this problem.

I'm building an application that given a time-zone, tells you what time in that location it is. It works great when I'm working with locations where the timezone is GMT (UTC), but fauils miserably if the timezone on the host machine is anything else, as it will still add the time to the host machine regardless.

So I was thinking what I have to do, is convert the machine time, into UTC (using getUTCDate() etc), and use that as a base. I was wondering if that's the right way to go, or if there's any better way t开发者_运维百科o do it.

Any help would be appreciated.

Thanks in advance,

UPDATE After Eugeny89's answer, I modified my code and created this method to convert the current date to UTC for me. Just wondering if that's the best way to go about it.

private function convertToUTC(dtDate:Date):Date{
            dtDate.setTime(dtDate.getTime() + (dtDate.getTimezoneOffset() * 60000))
            return dtDate;
}


Use getTimezoneOffset() (difference in minutes between users time and UTC time) or getUTCHours() of class Date. See manual for more details

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜