Home > Backend Development > PHP Tutorial > Example of php timestamp conversion_PHP tutorial

Example of php timestamp conversion_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:34:52
Original
766 people have browsed it

The following example produces the result:

Copy the code The code is as follows:

array(3) { ["yesterday" ]=> array(2) { [0]=> int(1395874800) [1]=> int(1395961199) } ["today"]=> array(2) { [0]=> int (1395961200) [1]=> int(1396047599) } ["tomorrow"]=> array(2) { [0]=> int(1396047600) [1]=> int(1396133999) } }

Copy code The code is as follows:

//Date conversion of yesterday, today and tomorrow
//($startstr Today’s start timestamp)
//Return 0:00 and 23:59:59 of (yesterday, today and tomorrow)
function alldaytostr($startstr) {
$oneday_count = 3600 * 24; //How many seconds are there in a day
//Tomorrow
$tomorrow_s = $startstr + $oneday_count; //Start tomorrow
$tomorrow_e = $tomorrow_s + $oneday_count - 1; //Ends tomorrow
//Yesterday
$yesterday_s = $startstr - $oneday_count; //Starts yesterday
$yesterday_e = $startstr - 1; // Ended yesterday
//Ended today
$today_e = $tomorrow_s - 1;
//Yesterday, today and tomorrow at 0:00 and 23:59:59 of the day are combined into an array
$allday_array = array ('yesterday' => array($yesterday_s, $yesterday_e),
'today' => array($startstr, $today_e),
'tomorrow' => array($tomorrow_s, $tomorrow_e ));
return $allday_array;
}
//Start time of the day
$btime = date('Y-m-d'.'00:00:00',time());
//Convert to "start" timestamp
$btimestr = strtotime($btime);
var_dump(alldaytostr($btimestr));

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/747676.htmlTechArticleThe following example yields the result: Copy the code The code is as follows: array(3) { ["yesterday"]= array( 2) { [0]= int(1395874800) [1]= int(1395961199) } ["today"]= array(2) { [0]= int(1395961200) [...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template