Home > php教程 > php手册 > php时间戳转换的示例

php时间戳转换的示例

WBOY
Release: 2016-06-06 20:23:39
Original
1232 people have browsed it

PHP获

以下例子得出结果:

复制代码 代码如下:


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) } }

复制代码 代码如下:


//昨天,,今天和明天的日期转换   
//($startstr 今天开始时间戳)
//返回(昨天,今天和明天)的0点和23点59分59秒
function alldaytostr($startstr) {
 $oneday_count = 3600 * 24;  //一天有多少秒
 //明天
 $tomorrow_s = $startstr + $oneday_count;    //明天开始
 $tomorrow_e = $tomorrow_s + $oneday_count - 1;  //明天结束
 //昨天
 $yesterday_s = $startstr - $oneday_count;  //昨天开始
 $yesterday_e = $startstr - 1;   //昨天结束
 //今天结束
 $today_e = $tomorrow_s - 1;
 //昨天、今天和明天 0点和当天23点59分59秒合并成数组
 $allday_array = array('yesterday' => array($yesterday_s, $yesterday_e),
  'today' => array($startstr, $today_e),
  'tomorrow' => array($tomorrow_s, $tomorrow_e));
 return $allday_array;
}
//当天开始时间
$btime = date('Y-m-d'.'00:00:00',time());
//转换成“开始”的时间戳
$btimestr = strtotime($btime);
var_dump(alldaytostr($btimestr));

?>

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template