ITeye博客

获取昨天,今天,明天的时间

lylan · 2015-01-28 20:08 · PHP · 编程语言 · Markdown

在php的Date类里面有一个非常强大的时间函数,能很随意的获取指定的时间日期

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

strtotime(string $time [, $now = time()])  

该函数预期接收一个含美国英语日期格式的字符串尝试将其解析为Unix时间戳,其值相对于now参数给出的时间,如果没有提供此参数,则用系统的当前时间。

date("Y-m-d",strtotime("now"));    //获取当前时间的时间戳,并转化为"Y-m-d"格式
date("Y-m-d",strtotime("+1day"));  //获取明天的时间
strtotime("-1 day");   //获取昨天的时间戳
strtotime("+1 week 2days 4hours 2seconds"); //一周2天4小时2秒后
strtotime("next monday");  //下周一
date("Y-m-d",strtotime("next month last mondy"));  //下周的最后一个周一
date("Y-m-d",strtotime("+10years"));  //十年后
date("Y-m-d",strtotime("+10year"));  //同样显示十年后的时间

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。