php时间戳转实例代码
来源:互联网 发布:魔法王座升阶数据大全 编辑:程序博客网 时间:2024/06/16 05:24
PHP获取“今天的时间戳”,再通过“今天”获取昨天和明天0点和23:59:59的时间戳。
结果:
//php时间戳
//昨天,今天和明天的日期转换
//($startstr 今天开始时间戳)
//返回(昨天,今天和明天)的0点和23点59分59秒
function alldaytostr($startstr) {
$oneday_count = 3600 * 24; //一天有多少秒
//明天
$tomorrow_s = $startstr + $oneday_count; //明天开始
$tomorrow_e = $tomorrow_s + $oneday_count - 1; //明天结束
//昨天 www.jbxue.com
$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));
?>
结果:
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//php时间戳
//昨天,今天和明天的日期转换
//($startstr 今天开始时间戳)
//返回(昨天,今天和明天)的0点和23点59分59秒
function alldaytostr($startstr) {
$oneday_count = 3600 * 24; //一天有多少秒
//明天
$tomorrow_s = $startstr + $oneday_count; //明天开始
$tomorrow_e = $tomorrow_s + $oneday_count - 1; //明天结束
//昨天 www.jbxue.com
$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));
?>
0 0
- php时间戳转实例代码
- unixtime时间戳 转 年月日(PHP代码函数)
- 年月日转 unixtime时间戳(PHP代码函数)
- Python时间戳与时间字符串互相转换实例代码
- php 时间戳的使用(代码)
- PHP时间戳代码 上周一等
- php显示时间代码
- PHP显示时间代码
- PHP采集代码实例
- PHP BOT实例代码
- php代码refine实例
- PHP分页实例代码
- php 时间转化函数实例
- android开发实例时间戳转时间
- php如何修改SESSION的生存存储时间的实例代码
- PHP时间戳与日期之间转换的实例介绍
- 时间戳防盗链实例--七牛云(php)
- php显示服务器时间代码
- bsoj1375 tarjan离线求lca
- 黑马程序员_4_如何修改TreeMap集合的root?
- 《黑马程序员》 读写锁的使用练习
- 《黑马程序员》 读写锁之缓存系统
- poj 2239 Selecting Courses 二分图最大匹配
- php时间戳转实例代码
- php根据年月获取季度示例
- Web编程学习六:使用Apache olingo将JPA数据库操作转化为RESTful Web Service
- 有一种渣,叫做由内而外的渣,就是我
- MSChart安装步骤
- 黑马程序员-有关包装类的总结
- 黑马程序员-有关Collection的总结
- 第四、五周作业
- 网络121第5周实验——GUI编程及JDK API的使用