In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces php timestamp format how to display friendly time function, the content is very detailed, interested friends can refer to reference, hope to be helpful to everyone.
The general idea is as follows:
If it's a new year and more than 3 days, it's displayed as a specific time.
If it's today's
If it's within a minute, it shows seconds ago.
If it's within an hour, it shows minutes ago.
If it's today and more than an hour, it's hours ago.
If it was yesterday, what time was it yesterday?
If it's the day before yesterday, what time is it?
If it is longer than three days (no new year), it will be displayed as the month and day.
According to the above ideas, it is not difficult to write the implementation code:
The implementation code is as follows:
The copy code is as follows:
//Format friendly display time
function formatTime($time){
$now=time();
$day=date('Y-m-d',$time);
$today=date('Y-m-d');
$dayArr=explode('-',$day);
$todayArr=explode('-',$today);
//Days of distance. This method is not necessarily accurate beyond 30 days, but it is accurate within 30 days, because a month may be 30 days or 31 days.
$days=($todayArr[0]-$dayArr[0])*365+(($todayArr[1]-$dayArr[1])*30)+($todayArr[2]-$dayArr[2]);
//Seconds of distance
$secs=$now-$time;
if($todayArr[0]-$dayArr[0]>0 && $days>3){//New Year and more than 3 days
return date('Y-m-d',$time);
}else{
if($days
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.