Getting unix timestamp in milliseconds in PHP5 and Actionscript3

后端 未结 12 2576
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 09:58

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

public static function getTimeStamp():uint
        {
            var now:Date =          


        
12条回答
  •  太阳男子
    2020-12-16 10:37

    I recently had this problem to get a timestamp in milliseconds. To just multiply the unix timestamp by 1000 did not resolve the problem because i had to compare two database entrys very precicely. Aparently the php datetime object can´t handle milliseconds/microseconds but its stored in the datetime string anyway. So here is my solution:

    $dateObject = new \DateTime('2015-05-05 12:45:15.444', new \DateTimeZone('Europe/London')); $millis = $dateObject->format('v'); echo $dateObject->getTimestamp()*1000+$millis;

    This should also work with microseconds if you use format->('u') (and of course multiply the timestamp by 1000000) instead. I hope you find this useful.

提交回复
热议问题