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