IT源码网

php时间类

sanshao 2021年02月16日 编程语言 409 0

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.总结

时间函数还需要不断完善

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!