首页 > PHP教程 > php开发知识文章

PHP 时间函数strtotime的使用技巧

本文主要介绍了PHP 时间函数strtotime的使用技巧。分享给大家供大家参考,欢迎大家的学习。

时间加减

 

//当前时间年份+1
$date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1));

PHP函数strtotime,对时间进行加减:

int strtotime ( string time [, int now] )

返回类型 int

函数用于时间转换和加减。

//date()格式化时间返回String类型。
////加一年
$date_year = date('Y-m-d', strtotime("$date + 1 year"));
echo $date_year;

//加一天
$date_tomorrow = date('Y-m-d', strtotime("2009-06-26 + 1 day"));
echo $date_tomorrow;

//加一周
$date_week = date('Y-m-d', strtotime("$date + 1 week"));
echo $date_week;

Unix时间戳(timestamp)转换工具:

http://dev.yuqingqi.com/unixtime/

以上就是本文PHP 时间函数strtotime的使用技巧的全部内容,希望本文所述对大家PHP程序设计有所帮助。

关闭
感谢您的支持,我会继续努力!
扫码打赏,建议金额1-10元


提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。