tradekey1h大佬:
把秒数转换成X天X小时X分X秒,保留2位精度。
总感觉这个写法笨笨的,有大佬能改进吗?
function htime($time,$keep=2){
if(is_numeric($time)){
$day = $hour = $min = $sec = 0;
$time_array = array();
if($time >= 3600*24){
$day = floor($time/(3600*24));
if($day > 0){
$time_array[] = "{$day}d";
}
$time = $time%(3600*24);
}
if($time >= 3600){
$hour = floor($time/3600);
if($hour > 0){
$time_array[] = "{$hour}h";
}
$time = ($time%3600);
}elseif($day > 0){
$time_array[] = "0h";
}
if($time >= 60){
$min = floor($time/60);
if($min > 0){
$time_array[] = $min."m";
}
$time = ($time%60);
}else{
$time_array[] = "0m";
}
$time_array[] = "{$time}s";
return implode(”, array_slice($time_array, 0, $keep));
}else{
return FALSE;
}
}
apdc大佬:
- window.setTimeout(countdown,1000);
- total_days = delta_T/(24*60*60*1000);//总天数
- total_show = Math.floor(total_days);//实际显示的天数
- total_hours = (total_days – total_show)*24;//剩余小时
- hours_show = Math.floor(total_hours);//实际显示的小时数
- total_minutes = (total_hours – hours_show)*60;//剩余的分钟数
- minutes_show = Math.floor(total_minutes);//实际显示的分钟数
- total_seconds = (total_minutes – minutes_show)*60;//剩余的分钟数
- seconds_show = Math.floor(total_seconds);//实际显示的秒数
- show_time.innerHTML = "距离2021年3月1日还有:" + total_show + "天" + hours_show + "时" + minutes_show + "分" + seconds_show + "秒";
llmwxt大佬:
不懂PHP
屌也只是一般尺寸!
dabiaoge大佬:
屌还行,PHP不行,帮不了你
liang0754大佬:
https://blog.csdn.net/haibo0668/article/details/82658288
南京扛把子大佬:
屌还行,PHP不行,帮不了你
我有个朋友想看看
大广大佬:
屌还行,上面的大佬已经有答案了,进来秀下jj
Evan大佬:
- function secondsToTime($seconds) {
- $dtF = new \DateTime(‘@0’);
- $dtT = new \DateTime("@$seconds");
- return $dtF->diff($dtT)->format(‘%a days, %h hours, %i minutes and %s seconds’);
- }
- echo secondsToTime(1640467);
- # 18 days, 23 hours, 41 minutes and 7 seconds
https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds
tradekey1h大佬:
https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds
需要从第一个非0单位开始,保留最多2个精度。
orz2大佬:
- $day = floor($a / DAY);
- $hour = floor(($a % DAY) / HOUR);
- $minute = floor((($a % DAY) % HOUR) / MINUTE);
- $sec = (($a % DAY) % HOUR) % MINUTE;
- echo $day . "天" . $hour . "时". $minute. "分" . $sec . "秒";
评论前必须登录!
注册