zl程序教程

您现在的位置是:首页 >  后端

当前栏目

php时间戳转换的示例

PHP转换 时间 示例
2023-06-13 09:15:24 时间

以下例子得出结果:

复制代码代码如下:

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

//昨天,今天和明天的日期转换   
//($startstr今天开始时间戳)
//返回(昨天,今天和明天)的0点和23点59分59秒
functionalldaytostr($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));

?>