php时间类

1.需求

数据库的时间都是用10个长度的时间戳存储,拿出来的时候要转为更易读的格式

2.例子

<?php
class Mydate{

    public function get_millisecond()
    {
        $time = explode(" ", microtime());
        $time = $time[1] . ($time[0] * 1000);
        $time2 = explode(".", $time);
        $time = $time2[0];
        return $time;
    }

    public function get_now()
    {
        return time();
    }

    public function unix_to_human($unixtime,$fmt='Y-m-d H:i:s')
    {
        return date($fmt,$unixtime);
    }

    public function human_to_unix($humantime)
    {
        return strtotime($humantime);
    }
}
$obj =new Mydate();
$c = $obj->unix_to_human(time());
echo $obj->human_to_unix($c);

3.总结

时间函数还需要不断完善

原文地址:https://www.cnblogs.com/norm/p/6246500.html