Example of conversion between PHP timestamp and date_PHP Tutorial

WBOY
Release: 2016-07-21 15:11:58
Original
1068 people have browsed it

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 0

echo 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

1.php time conversion function strtotime("today") date("Y-m-d H:i",$unixtime ) 2. Get today’s zero time timestamp in php. To get the zero time unix timestamp, you can use $todaytime=strtot...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template