最近在写一个打卡的项目。结果发现“秒”已经不能满足这群小B的需求了,查了一些资料于是就有了这篇文章。
 
public function index() { $msectime = $this->getMsecTime(); $mescdate =
$this->getMsecToMescdate($msectime); $msectime2 =
$this->getDateToMesc($mescdate); echo $msectime."<br />"; echo $mescdate."<br
/>"; echo $msectime2."<br />"; } /** * 获取毫秒级别的时间戳 */ public function
getMsecTime() { list($msec, $sec) = explode(' ', microtime()); $msectime =
(float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return
$msectime; } /** * 毫秒转日期 */ public function getMsecToMescdate($msectime) {
$msectime = $msectime * 0.001; if(strstr($msectime,'.')){
sprintf("%01.3f",$msectime); list($usec, $sec) = explode(".",$msectime); $sec =
str_pad($sec,3,"0",STR_PAD_RIGHT); }else{ $usec = $msectime; $sec = "000"; }
$date = date("Y-m-d H:i:s.x",$usec); return $mescdate = str_replace('x', $sec,
$date); } /** * 日期转毫秒 */ public function getDateToMesc($mescdate) { list($usec,
$sec) = explode(".", $mescdate); $date = strtotime($usec); $return_data =
str_pad($date.$sec,13,"0",STR_PAD_RIGHT); return $msectime = $return_data; }
效果如图:


友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信