C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

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()));
}

 

posted on 2018-09-15 20:24  思齐_  阅读(3855)  评论(0编辑  收藏  举报