中以毫秒为单位获取

中以毫秒为单位获取

本文介绍了在 PHP5 和 Actionscript3 中以毫秒为单位获取 unix 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Actionscript 中,以毫秒为单位的 Unix 时间戳可以这样获得:

In Actionscript, the Unix timestamp in milliseconds is obtainable like this:

public static function getTimeStamp():uint
        {
            var now:Date = new Date();
            return now.getTime();
        }

该文档清楚地说明了以下内容:

The doc clearly states the following:

getTime():Number 返回次数自 1 月 1 日午夜以来的毫秒数,1970 年,世界时,日期对象.

当我跟踪它时,它返回以下内容:

When I trace it, it returns the following:

824655597

因此,824655597/1000/60/60/24/365 = 0.02 年.这显然是不正确的,应该是 39 年左右.

So, 824655597 / 1000 / 60 / 60 / 24 / 365 = 0.02 years.This is obviously not correct, as it should be around 39 years.

问题 1:这里出了什么问题?

Question #1: What's wrong here?

现在,进入 PHP 部分:我也在尝试获取以毫秒为单位的时间戳.microtime() 函数返回字符串 (0.29207800 1246365903) 或浮点数 (1246365134.01),具体取决于给定的参数.因为我认为时间戳很容易,所以我打算自己做.但是现在我已经尝试并注意到了这个浮动,并将其与我在 Actionscript 中的问题结合起来,我真的不知道.

Now, onto the PHP part: I'm trying to get the timestamp in milliseconds there as well. The microtime() function returns either a string (0.29207800 1246365903) or a float (1246365134.01), depending on the given argument. Because I thought timestamps were easy, I was going to do this myself. But now that I have tried and noticed this float, and combine that with my problems in Actionscript I really have no clue.

问题 2:我应该如何让它返回 Unix 时间戳中的毫秒数?

Question #2: how should I make it returns the amount of milliseconds in a Unix timestamp?

时间戳应该很简单,我可能遗漏了一些东西……抱歉.提前致谢.

Timestamps should be so easy, I'm probably missing something.. sorry about that. Thanks in advance.

我自己回答了第一个问题.见下文.
我自己也回答了第二个问题.见下文.48小时内不能接受答复.

Answered the first question by myself. See below.
Answered second question by myself as well. See below. Can't accept answer within 48 hours.

推荐答案

对于 actionscript3,new Date().getTime() 应该可以工作.

For actionscript3, new Date().getTime() should work.

在 PHP 中,您可以简单地调用 time() 来获取自 1970 年 00 月 1 日以来经过的时间:格林威治标准时间 00:00(以秒为单位).如果您想要毫秒,只需执行 (time()*1000).

In PHP you can simply call time() to get the time passed since January 1 1970 00:00:00 GMT in seconds. If you want milliseconds just do (time()*1000).

如果您使用 microtime() 将第二部分乘以 1000获得毫秒.将第一部分乘以 1000 以获得毫秒数并四舍五入.然后将两个数字相加.瞧.

If you use microtime() multiply the second part with 1000 to get milliseconds. Multiply the first part with 1000 to get the milliseconds and round that. Then add the two numbers together. Voilá.

这篇关于在 PHP5 和 Actionscript3 中以毫秒为单位获取 unix 时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:02