翻译的ActionScript日期从UTC为本地时间与历元毫秒 [英] Translating ActionScript Date from UTC to local time with milliseconds from epoch

查看:700
本文介绍了翻译的ActionScript日期从UTC为本地时间与历元毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个对我的<跟进href="http://stackoverflow.com/questions/11632421/creating-actionscript-date-object-from-mysql-utc-timestamp-string">$p$pvious问题。在我的解决方案来获得当前的时间,我需要加/减偏移:

This is a follow up on my previous question. In my solution to get current time, I need to add/subtract offset:

var createDate:Date = new Date();
var offset:Number = createDate.getTimezoneOffset() * 60 * 1000; 
createDate.time = parseInt("1343174921") * 1000 - offset; // subtracting offset

要获得正确的时间,我不得不减去偏移量(纯猜测)。我怎么知道加上或减去偏移?该文档使用getTimezoneOffset 说:

To get correct time, I had to subtract offset(pure guess). How do I know to subtract or add offset? The documentation for getTimezoneOffset says:

此值为分钟,你需要添加到数   计算机的本地时间与UTC相等。如果您的计算机的时间设置   晚于UTC,则该值将是负面的。

this value is the number of minutes you need to add to the computer's local time to equal UTC. If your computer's time is set later than UTC, the value will be negative.

有没有一种简单的方法来计算出,如果计算机的时间设置晚/早于UTC,让我知道,如果我需要增加或减少偏移?

Is there an easy way to figure out if computer's time is set later/earlier than UTC so that I know if I need to add or subtract offset?

更新我检查了数据库和我存储在已创建7/25/2012晚上八时作为一款入门 1343282417 (我用的 UTC_TIMESTAMP()以店内为准)。当我将它插入Unix时间戳转换,我得到周四,2012年7月26日6点00分17秒GMT 。所以我很困惑为什么MySQL的UTC_TIMESTAMP(即假设返回当前UTC日期和时间)给了我一个不同的日期。我在本地工作的这两个MySQL数据库,PHP和Flash code是在单台机器。

update I've checked the database and I'm storing an entry that was created on 7/25/2012 at 8pm as 1343282417 (I'm using UTC_TIMESTAMP() to store date). When I plug it into Unix timestamp converter I get Thu, 26 Jul 2012 06:00:17 GMT. So I'm confused why does MySql's UTC_TIMESTAMP ( that suppose to return the current UTC date and time) gives me a different date. I'm working locally both the MySQL db, php and Flash code are on single machine.

推荐答案

您的问题是pretty的多你的答案,不是吗?

Your question is pretty much your answer, isn't it?

此值为分钟,你需要添加到计算机的数量   当地时间等于UTC。如果您的计算机的时间晚于集   UTC,则该值将是负面的。

this value is the number of minutes you need to add to the computer's local time to equal UTC. If your computer's time is set later than UTC, the value will be negative.

这意味着你需要随时添加使用getTimezoneOffset 到当地日期以获得UTC日期

Meaning that you need to always ADD getTimezoneOffset to the local Date to get the UTC Date

因此​​,

var now:Date=new Date();

var utcOffset=now.getTimezoneOffset() * 60 * 1000;

var utcNow:Date=new Date(now.valueOf() + utcOffset);

您现在在UTC时间 utcNow

注意: utcNow 是UTC时间(这是在用户的时区当前UTC时间只是一个虚假的再presentation ,也就是说,一个的toString()将用户原有的时区追加。要获得UNIX时间戳,使用 utcNow.valueOf()

Note: utcNow is just a false representation of the utc time (it is the current UTC time in the user's timezone. That is, a toString() will have the user's original timezone appended. To get the UNIX timestamp, use utcNow.valueOf()

有内置​​的API函数 GETUTCDATE getUTCFullYear getUTCHours getUTCMinutes getUTCMilliseconds getUTCMonth getUTCSeconds ,您可以在原来的(现在)调用Date对象来获得这些值只。

There are inbuilt API functions getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes, getUTCMilliseconds, getUTCMonth, and getUTCSeconds which you can call on the original (now) Date object to get those values only.

这篇关于翻译的ActionScript日期从UTC为本地时间与历元毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆