Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the calculation time functions of php?

Shulou Source: shulou.com Published: 2022-06-03 07:51:45 10月24日 Update

This article mainly explains "what are the php computing time functions". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the php computing time functions"!

First, function realization

Example 1:

The copy code is as follows:

Function time_tran ($the_time) {

$now_time = date ("Y-m-d H:i:s", time () + 8 / 60 / 60)

$now_time = strtotime ($now_time)

$show_time = strtotime ($the_time)

$dur = $now_time-$show_time

If ($dur

< 0){ return $the_time; }else{ if($dur < 60){ return $dur.'秒前'; }else{ if($dur < 3600){ return floor($dur/60).'分钟前'; }else{ if($dur < 86400){ return floor($dur/3600).'小时前'; }else{ if($dur < 259200){//3天内 return floor($dur/86400).'天前'; }else{ return $the_time; } } } 实例2: 复制代码 代码如下: 实例3: 复制代码 代码如下: function formatTime($date) { $str = ''; $timer = strtotime($date); $diff = $_SERVER['REQUEST_TIME'] - $timer; $day = floor($diff / 86400); $free = $diff % 86400; if($day >

0) {

Return $day. "days ago"

} else {

If ($free > 0) {

$hour = floor ($free / 3600)

$free = $free% 3600

If ($hour > 0) {

Return $hour. "hours ago"

} else {

If ($free > 0) {

$min = floor ($free / 60)

$free = $free 60

If ($min > 0) {

Return $min. "minutes ago"

} else {

If ($free > 0) {

Return $free. "seconds ago"

} else {

Return 'just'

}

}

} else {

Return 'just'

}

}

} else {

Return 'just'

}

}

}

Example 4:

The copy code is as follows:

Function time_tran ($the_time) {

$now_time = date ("Y-m-d H:i:s", time () + 8 / 60 / 60)

$now_time = strtotime ($now_time)

$show_time = strtotime ($the_time)

$dur = $now_time-$show_time

If ($dur < 0) {

Return $the_time

} else {

If ($dur < 60) {

Return $dur.' Seconds ago.

} else {

If ($dur < 3600) {

Return floor ($dur/60).' Minutes ago.

} else {

If ($dur < 86400) {

Return floor ($dur/3600).' An hour ago.

} else {

If ($dur < 259200) {/ / within 3 days

Return floor ($dur/86400).' Days ago.

} else {

Return $the_time

}

}

}

}

}

}

Second, the realization of the class

The copy code is as follows:

Tags: Code time examples hours functions content learning practical deeper interest practicality practicality years ago simple operation way method week more friends website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Huawei Shulou Technology macOS