In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
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:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.