您的位置:首页 > 编程语言 > PHP开发

PHP获取时间戳

2016-04-11 15:09 489 查看
// 获取当前时间的时间代码:
echo "当前时间:" . date("Y-m-d H:i:s") . '
';
echo "当前时间时间戳:" . strtotime(date('Y-m-d')) . '
';

// 获取前一天时间的时间代码:
echo "前一天时间:" . date("Y-m-d H:i:s", strtotime("-1 day")) . '
';
echo "前一天时间时间戳:" . strtotime(date("Y-m-d H:i:s", strtotime("-1 day"))) . '
';

// 获取明天凌晨的时间代码:
echo "明天凌晨的时间:" . (date('Y-m-d 00:00:00', strtotime('+1 day'))) . '
';
echo "明天凌晨的时间戳:" . strtotime(date('Y-m-d', strtotime('+1 day'))) . '
';

// 获取明天23:59:59的时间代码:
echo "明天23:59:59的时间:" . (date('Y-m-d 23:59:59', strtotime('+1 day'))) . '
';
echo "明天23:59:59的时间戳:" . strtotime(date('Y-m-d 23:59:59', strtotime('+1 day'))) . '
';

// 其它参考代码:
echo "一周后:" . date("Y-m-d", strtotime("+1 week")) . '
';
echo "一周零两天四小时两秒后:" . date("Y-m-d G:H:s", strtotime("+1 week 2 days 4 hours 2 seconds")) . '
';
echo "下个星期四:" . date("Y-m-d", strtotime("next Thursday")) . '
';
echo "上个周一:" . date("Y-m-d", strtotime("last Monday")) . '
';
echo "一个月前:" . date("Y-m-d", strtotime("last month")) . '
';
echo "一个月后:" . date("Y-m-d", strtotime("+1 month")) . '
';
echo "十年后:" . date("Y-m-d", strtotime("+10 year")) . '
';


结果:

当前时间:2016-06-14 10:06:07
当前时间时间戳:1465833600
前一天时间:2016-06-13 10:06:07
当前时间时间戳:1465783567
明天凌晨的时间:2016-06-15 00:00:00
明天凌晨的时间戳:1465920000
明天23:59:59的时间:2016-06-15 23:59:59
明天23:59:59的时间戳:1466006399
一周后:2016-06-21
一周零两天四小时两秒后:2016-06-23 14:14:09
下个星期四:2016-06-16
上个周一:2016-06-13
一个月前:2016-05-14
一个月后:2016-07-14
十年后:2026-06-14
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  时间戳