如何用PHP实现获取当前时间戳、日期及毫秒值的三种方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计558个文字,预计阅读时间需要3分钟。
php获取当前时间戳并精确到毫秒,首先封装一个获取时间戳的方法:第一种方法:时间戳13位 + '/' + 时间戳到毫秒 + '@return bool|string' / public static function getMillisecond() {
php 获取当前时间戳、日期并精确到毫秒首先,我们封装一个获取时间戳的方法:
第一种方法:时间戳13位
/** * 获取时间戳到毫秒 * @return bool|string */ public static function getMillisecond(){ list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectimes = substr($msectime,0,13); }
其次,调用这个方法,并打印结果:
看看结果:
成功获取到了,时间戳且精确到了毫秒!---- 13位,自己数数。
本文共计558个文字,预计阅读时间需要3分钟。
php获取当前时间戳并精确到毫秒,首先封装一个获取时间戳的方法:第一种方法:时间戳13位 + '/' + 时间戳到毫秒 + '@return bool|string' / public static function getMillisecond() {
php 获取当前时间戳、日期并精确到毫秒首先,我们封装一个获取时间戳的方法:
第一种方法:时间戳13位
/** * 获取时间戳到毫秒 * @return bool|string */ public static function getMillisecond(){ list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectimes = substr($msectime,0,13); }
其次,调用这个方法,并打印结果:
看看结果:
成功获取到了,时间戳且精确到了毫秒!---- 13位,自己数数。

