本文介绍了是否有等同于 C#.NET DateTime.Now.ToString("yyyyMMddHHmmssfff") 的 PHP7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑这个 C#.NET 代码:
Considering this C#.NET code:
DateTime.Now.ToString("yyyyMMddHHmmssfff")
,PHP 中是否有等价物?
, is there any equivalent in PHP?
目前,我使用以下内容:
For the moment, I use the following:
$date = new DateTime();
$timestamp = $date->getTimestamp();
$formatted_timestamp = gmdate("YmdHms", $timestamp) . round(microtime(true) * 1000);
但是,它不会输出相同的结果(从秒开始).
However, it doesn't output the same results (from the seconds).
推荐答案
由于您已经在使用 DateTime
对象,您可以简单地对其进行格式化:
Since you're already using a DateTime
object, you could simply format it:
$date = new DateTime();
return $date->format('YmdHisv');
'v'
就是您要查找的内容(毫秒).
the 'v'
is what you're looking for (milliseconds).
注意:这需要 PHP 7.1
,如果您在不带参数的情况下实例化 DateTime()
,以获得一些非 0 毫秒(或微)秒.
Caution: this requires PHP 7.1
, if you instantiate DateTime()
with no arg, in order to obtain some non-0 milli (or micro) seconds.
这篇关于是否有等同于 C#.NET DateTime.Now.ToString("yyyyMMddHHmmssfff") 的 PHP7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!