Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

3.7. 日期函数

3.7.1. strtotime

$start_date = date("Y-m-d H:i:s", strtotime('next Saturday'));
$start_week = date("Y-m-d", strtotime("last week"));
$end_week = date("Y-m-d", strtotime("this week"));
$sat = strtotime('saturday');
$start_date = date("Y-m-d H:i:s", strtotime('Saturday'));
$start = strtotime('2 weeks ago');
			

3.7.2. 日期比较

			
if(strftime('%Y-%m-%d',strtotime('2009-04-19')) <= date('Y-m-d')){
	to-do ...
}
			
			

3.7.3. date()

格式化日期 2011-01-07T12:22:11 各种用法常见于Java提供的接口

echo date("Y-m-d\TH:i:s", strtotime("2011-01-07 12:22:11"));			
			

3.7.4. DateTime

$source = '2012-07-31';
$date = new DateTime($source);
echo $date->format('d.m.Y'); // 31.07.2012
echo $date->format('d-m-Y'); // 31-07-2012
			

3.7.5. ISO 8601

echo date("Y-m-d\TH:i:s", strtotime("2011-01-07 12:22:11"));

echo date('c',time());

2016-08-23T16:01:08+08:00