Home > Backend Development > PHP Tutorial > PHP 时间戳取整问题

PHP 时间戳取整问题

WBOY
Release: 2016-06-23 14:01:26
Original
1698 people have browsed it

时间戳是10位的,取的是当前时间戳:
$nowtime = strtotime(date('Y-m-d H:i:s')); //当前时间戳
得到的 $nowtime 有时候是 1393834011,有时候是 1393834062
我想实现一功能,怎么样能让时间戳取整变成这样的:1393834020,1393834070?
不能直接这么写:strtotime(date('Y-m-d H:i'));


回复讨论(解决方案)

   $time=time();
 $time=$time/10;
 $time_zhengshu=floor($time);
 $time_zhengshu=$time_zhengshu*10;
 echo "$time_zhengshu";
 ?> 不知道这是不是你想要的 测试都是尾数为0.

echo round(1393834011 + 9, -1); //1393834020
echo round(1393834062 + 9, -1); //1393834070

float round ( float $val [, int $precision ] )

返回将 val 根据指定精度 precision(十进制小数点后数字的数目)进行四舍五入的结果。precision 也可以是负数或零(默认值)。 

楼上+1

   $time=time();
 $time=$time/10;
 $time_zhengshu=floor($time);
 $time_zhengshu=$time_zhengshu*10;
 echo "$time_zhengshu";
 ?> 不知道这是不是你想要的 测试都是尾数为0. 没看到楼主的需求,以为只是取整。徐版主的答案正确!

floor($time / 10) * 10

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template