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

Example of php timestamp conversion_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:34:52764browse

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) [...
Statement:
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