使用'2016-07-04 00:00:00.000'格式在PHP中获取当前日期和时间[复制]
问题描述:
This question already has an answer here:
I am using mssql db with php. Which PHP function can return the current datetime. (i.e.) I want the current date and time to be saved in the following format say for example,
2016-07-04 11:10:05.000
Thanks!
</div>
此问题已经存在 这里有一个答案: p>
-
如何在yyyy-mm-dd中获取GMT日期hh:mm:PHP中的ss
6 answers
span>
li>
ul>
div>
2016-07-04 11:10:05.000 code > pre>
谢谢! p> div>
答
Use date->format http://php.net/manual/it/function.date.php
$date = new DateTime('2000-01-01'); echo $date->format('Y-m-d H:i:s.u');
答
With "date" you can format the output and with "time" you get the current unix time.
Example
echo date("Y-m-d H:i:s.u", time());
Documentation: http://php.net/manual/it/function.date.php
答
12-hour format
date("Y-m-d h:i:s.u")
24-hour format
date("Y-m-d H:i:s.u")