PHP 指定时间戳 加上指定秒、分钟、小时等

编程知识 行业动态 更新时间:2024-06-13 00:22:43
<?php
// 当前时间戳  格式:2019-03-13 18:00:00
echo date('Y-m-d H:i:s', strtotime('now'));

// 当前时间戳+1秒
echo date('Y-m-d H:i:s', strtotime('+1second'));

// 当前时间戳+1分
echo date('Y-m-d H:i:s', strtotime('+1minute'));

// 当前时间戳+1小时
echo date('Y-m-d H:i:s', strtotime('+1hour'));

// 当前时间戳+1天 
echo date('Y-m-d H:i:s', strtotime('+1day'));

// 当前时间戳+1周 
echo date('Y-m-d H:i:s', strtotime('+1week'));

// 当前时间戳+1月 
echo date('Y-m-d H:i:s', strtotime('+1month'));

// 当前时间戳+1年
echo date('Y-m-d H:i:s', strtotime('+1year'));

// 当前时间戳+12年,12月,12天,12小时,12分,12秒
echo date('Y-m-d H:i:s', strtotime('+12year 12month 12day 12hour 12minute 12second'));

$t = 1483967416; // 指定时间戳

echo $date = date('Y-m-d H:i:s', $t);

/*方法一*/

// 指定时间戳+1天
echo date('Y-m-d H:i:s', $t+1*24*60*60);

// 指定时间戳+1年
echo date('Y-m-d H:i:s', $t+365*24*60*60);

/*方法二*/

// 指定时间戳+1天
echo date('Y-m-d H:i:s', strtotime("+1day", $t));

// 指定时间戳+1年
echo date('Y-m-d H:i:s', strtotime("+1year", $t));

<?php
// 获取上个月第一天及最后一天
echo date('Y-m-01', strtotime('-1 month'));
echo date('Y-m-t', strtotime('-1 month'));

// 获取当月第一天及最后一天
echo $beginDate = date('Y-m-01', strtotime(date("Y-m-d")));
echo date('Y-m-d', strtotime("$beginDate +1 month -1 day"));

更多推荐

PHP 指定时间戳 加上指定秒、分钟、小时等

本文发布于:2023-04-03 03:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/52e563ed8b1e59795796b30f8c20c410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小时   时间   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!