---
title: "获取昨天，今天，明天的时间"
author: "lylan"
date: "2015-01-28T20:08:21Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2015-01-28T20:09:30Z"
id: 2180986
url: "https://lylan.iteye.com/blog/2180986"
---

在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"));  //同样显示十年后的时间
```