Home >Backend Development >PHP Tutorial >Example of conversion between PHP timestamp and date_PHP Tutorial
Time conversion function in 1.php
strtotime(“today”)
date("Y-m-d H:i",$unixtime)
Get today’s zero time timestamp in 2.php
To get the unix timestamp at zero point, you can use $todaytime=strtotime("today"),
Then use date("Y-m-d H:i",$todaytime) to convert to date.
Convert the timestamp in 3.php to date, and display different contents according to time, such as just now, minutes ago, hours ago, today, yesterday, etc.
/*Time conversion function*/
function transTime($ustime) {
$ytime = date("Y-m-d H:i",$ustime);$rtime = date("n month j day H:i",$ustime);
$htime = date("H:i",$ustime);
$time = time() - $ustime;$todaytime = strtotime("today");
$time1 = time() - $todaytime;
if($time < 60){$str = 'Just now';
}else if($time < 60 * 60){$min = floor($time/60);
$str = $min.'minutes ago';}else if($time < $time1){
$str = 'Today'.$htime;
}else{$str = $rtime;
}return $str;
}
In this function you can add more comparisons to make the displayed date more specific, such as adding seconds ago, the day before yesterday, etc. for more specific dates.
4.php Date is filled with 0 or not filled with 0echo date('Y-m-d'); displays 2012-08-08
echo date('Y-n-j'); displays 2012-8-8
http://www.bkjia.com/PHPjc/326832.html
www.bkjia.comtrue
http: //www.bkjia.com/PHPjc/326832.html
TechArticle