doukangbin9698 2015-06-13 10:23
浏览 133
已采纳

用PHP获取时间刻度

Consider this line of code in C#

ordernumber.Value = DateTime.Now.Ticks.ToString();

How to get same ordernumber.Value in PHP

$ordernumberValue = microtime(); //?

I try to this

echo microtime(true) * 10000000;

But get result string.length was difference. short length than C#.

  • 写回答

3条回答 默认 最新

  • 普通网友 2015-06-13 10:55
    关注

    From .NET documentation:

    DateTime.Ticks Property

    The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

    In PHP this is implemented simply as time():

    time

    Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

    microtime() similarly returns time in seconds and microseconds after decimal point, so it has greater precision. For some archaic reasons, the default value is a string, but if you pass true as first argument, you'll get a nice float:

    rr-@burza:~$ php -r 'echo microtime(true);'
    1434193280.3929%    
    

    So all you have to do is to scale the value returned by either time() or microtime() by a constant factor.

    According to Wikipedia, a nanosecond is equal to 1000 picoseconds or 1⁄1000 microsecond, or 1/1000000000 second. So 100 nanoseconds would mean 100/1000000000 microseconds, i.e. one .NET tick = 1/10000000 second, i.e. one second = 10000000 .NET ticks. Thus you need to multiply value returned by time() or microtime() by 10000000 like this:

    microtime(true) * 10000000
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题