php时间戳转换的示例
2014-03-31 16:51
465 查看
以下例子得出结果:
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秒
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));
?>
您可能感兴趣的文章:
相关文章推荐
- php数值转换时间及时间转换数值代码示例
- php数值转换时间及时间转换数值用法示例
- php时间戳转换的示例
- 用PHP实现URL转换短网址的算法示例
- php如何将获得的时间转换为北京时间
- PHP格式的UNIX时间戳转换为Javascript可用的时间戳
- 关于php读取excel的时间转换问题
- php中时间戳和日期格式的转换
- php日期转时间戳,指定日期转换成时间戳
- PHP实现十进制数字与二十六进制字母串相互转换操作示例
- php 将秒数转换为时间(年、天、小时、分、秒)
- php时间戳与日期转换
- 常用时间格式与PHP时间格式相互转换
- js的时间戳和php的时间戳转换需要…
- Javascript的时间戳和php的时间戳转换注意事项
- java 时间戳和PHP时间戳 的转换 php time()
- PHP对于Unix时间戳的转换
- PHP正则匹配日期和时间(时间戳转换)的实例代码
- php时间戳与字符串的相互转换
- php计算当前程序执行时间示例