php 日期处理 DateTime

获取所有的时区

print_r(timezone_abbreviations_list ());

获取毫秒级时间戳

// php7.1+ always has microseconds enabled, so we do not need this hack
if (PHP_VERSION_ID < 70100) {
  // 第一个参数:php 支持的日期和时间格式
$ts = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))); } else { $ts = new DateTime(null); } $ts->setTimezone(new DateTimeZone("PRC")); var_dump($ts->format("Y-m-d H:i:s.u")); // 2018-09-15 20:15:58.332000 win下只可以到三位,linux可以到六位

php支持的日期和时间格式

function utime()
{
    return (float) (vsprintf('%d.%06d', gettimeofday()));
}
原文地址:https://www.cnblogs.com/siqi/p/9652026.html