简体   繁体   English

将当前服务器时间转换为ISO 8601

[英]Convert current server time to ISO 8601

I must convert the server current time to this format: 我必须将服务器当前时间转换为以下格式:

2016-03-23T05:24:25.590000

I think this is an ISO 8601 (even if I don't understand what are the final numbers, supposedly microseconds). 我认为这是一个ISO 8601(即使我不明白最终的数字是多少,也可能是微秒)。

How can I do? 我能怎么做? Any help is welcome 欢迎任何帮助

The final numbers are the microseconds. 最终数字是微秒。 It is easy to output a given DateTime object $d in this format: 以这种格式输出给定的DateTime对象$d很容易:

echo $d->format('Y-m-d\TH:i:s.u');

It is not so easy, to get the current timestamp including microseconds, because constructing it with now only gets whole seconds. 要获得包括微秒在内的当前时间戳并非易事,因为now构造它只需要整整几秒钟。 You could go this way and append the microseconds manually: 您可以按照这种方式手动添加微秒:

echo date('Y-m-d\TH:i:s') . substr((string) microtime(), 1, 7);
// 2016-03-23T14:55:25.535678

See doc for microtime() and DateTime . 参见doc了解microtime()DateTime

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM