使用'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>

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")