Home  >  Article  >  Backend Development  >  PHP中的date函数跟time函数

PHP中的date函数跟time函数

WBOY
WBOYOriginal
2016-06-13 13:06:40863browse

PHP中的date函数和time函数。
time()函数是获取当前的时间戳 从1970年1月1日 零点 零分 零秒

date()函数是格式化时间戳的。有没有人知道他是怎么格式化的呢?比如我有个时间戳 我能不能自己计算出时间呢?time()时间戳获取的是秒钟的累积和。但是我试着用时间戳除以60等于分。再除以60等于小时 在除以24怎么就不对了呢?

------解决方案--------------------
楼主是说获取时间戳除以一天24小时得到天数加上1970年

获取现在的时间。

问题是一年365天还是366天啊?

就像直接得到月份也是,28天一个月,31也是一个月!
------解决方案--------------------
那个秒数只能算到天。因为闰年的存在,所以不能简单得出。
------解决方案--------------------
function todate($time) //将时间化为日期
{
$arr=getdate($time);
echo $arr[year],"年",$arr[mon],"月",$arr[mday],"日",$arr[hours],"时",$arr[minutes],"分",$arr[seconds],"秒";
}



完美解决
------解决方案--------------------

PHP code

function todate($time)       //将时间化为日期
{
$arr=getdate($time);
echo $arr[year],"年",$arr[mon],"月",$arr[mday],"日",$arr[hours],"时",$arr[minutes],"分",$arr[seconds],"秒";
} <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn