php 中的date和strtotime函数

编程入门 行业动态 更新时间:2024-10-07 16:17:06

php 中的date和strtotime<a href=https://www.elefans.com/category/jswz/34/1771370.html style=函数"/>

php 中的date和strtotime函数

all from : .strtotime.php


strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳


date_default_timezone_set('Asia/Shanghai');


计算昨天的时间,我们用:


date("Ymd",time()-3600);


可以的


另外我们还可以用strtotime()来简单的生成时间,例如:


//生成昨天的时间

date("Ymd",strtotime('yesterday'));

date("Ymd",strtotime('-1 day'));


//生成前天的时间

date("Ymd",strtotime('yesterday -1 day'));

date("Ymd",strtotime('-2 day'));


//生成3天之后的时间

date("Ymd",strtotime('+3 day'));


//生成一个月前的时间

date("Ymd",strtotime('-1 month'));



甚至还可以这么用:


//生成下个月最后一天的时间  - -!  看到这个,你明白了其实你可以用自然语言直接描述~~~php的strtotime()来任意取得自然时间~~太强大了~~

date("Ymd",strtotime('last day of next month'));


//下个周的星期一

date("Ymd",strtotime('next monday'));


strtotime()函数很好用,可以多看看相关技巧~~

更多推荐

php 中的date和strtotime函数

本文发布于:2024-02-07 02:54:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1752525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   php   date   strtotime

发布评论

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

>www.elefans.com

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