php時間戳轉(zhuǎn)換的示例
以下例子得出結(jié)果:
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) } }
<?php
//昨天,今天和明天的日期轉(zhuǎn)換
//($startstr 今天開始時間戳)
//返回(昨天,今天和明天)的0點(diǎn)和23點(diǎn)59分59秒
function alldaytostr($startstr) {
$oneday_count = 3600 * 24; //一天有多少秒
//明天
$tomorrow_s = $startstr + $oneday_count; //明天開始
$tomorrow_e = $tomorrow_s + $oneday_count - 1; //明天結(jié)束
//昨天
$yesterday_s = $startstr - $oneday_count; //昨天開始
$yesterday_e = $startstr - 1; //昨天結(jié)束
//今天結(jié)束
$today_e = $tomorrow_s - 1;
//昨天、今天和明天 0點(diǎn)和當(dāng)天23點(diǎn)59分59秒合并成數(shù)組
$allday_array = array('yesterday' => array($yesterday_s, $yesterday_e),
'today' => array($startstr, $today_e),
'tomorrow' => array($tomorrow_s, $tomorrow_e));
return $allday_array;
}
//當(dāng)天開始時間
$btime = date('Y-m-d'.'00:00:00',time());
//轉(zhuǎn)換成“開始”的時間戳
$btimestr = strtotime($btime);
var_dump(alldaytostr($btimestr));
?>
相關(guān)文章
PHP session文件獨(dú)占鎖引起阻塞問題解決方法
這篇文章主要介紹了PHP session文件獨(dú)占鎖引起阻塞,本文講解PHP使用默認(rèn)文件會話處理器時容易導(dǎo)致的阻塞問題解決方法,需要的朋友可以參考下2015-05-05
php 二維數(shù)組快速排序算法的實現(xiàn)代碼
這篇文章主要介紹了php 二維數(shù)組快速排序算法的實現(xiàn)代碼的相關(guān)資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10

