首页 > Web开发 > 详细

php时间类

时间:2017-01-03 22:29:50      阅读:240      评论:0      收藏: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.总结

时间函数还需要不断完善

php时间类

原文:http://www.cnblogs.com/norm/p/6246500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!