<?php
/**
* php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内)
*
* author:[email protected]
* date:2012-06-28 16:00:01
*/ $q = $_GET['q'] ? intval($_GET['q']) : 0; $text = '';
$now = time(); if ($q === 1) {// 今天
$text = '今天';
$beginTime = date('Y-m-d 00:00:00', $now);
$endTime = date('Y-m-d 23:59:59', $now);
} elseif ($q === 2) {// 昨天
$text = '昨天';
$time = strtotime('-1 day', $now);
$beginTime = date('Y-m-d 00:00:00', $time);
$endTime = date('Y-m-d 23:59:59', $now);
} elseif ($q === 3) {// 三天内
$text = '三天内';
$time = strtotime('-2 day', $now);
$beginTime = date('Y-m-d 00:00:00', $time);
$endTime = date('Y-m-d 23:59:59', $now);
} elseif ($q === 4) {// 本周
$text = '本周';
$time = '1' == date('w') ? strtotime('Monday', $now) : strtotime('last Monday', $now);
$beginTime = date('Y-m-d 00:00:00', $time);
$endTime = date('Y-m-d 23:59:59', strtotime('Sunday', $now));
} elseif ($q === 5) {// 上周
$text = '上周';
// 本周一
$thisMonday = '1' == date('w') ? strtotime('Monday', $now) : strtotime('last Monday', $now);
// 上周一
$lastMonday = strtotime('-7 days', $thisMonday);
$beginTime = date('Y-m-d 00:00:00', $lastMonday);
$endTime = date('Y-m-d 23:59:59', strtotime('last sunday', $now));
} elseif ($q === 6) {// 本月
$text = '本月';
$beginTime = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m', $now), '1', date('Y', $now)));
$endTime = date('Y-m-d 23:39:59', mktime(0, 0, 0, date('m', $now), date('t', $now), date('Y', $now)));
} elseif ($q === 7) {// 三月内
$text = '三月内';
$time = strtotime('-2 month', $now);
$beginTime = date('Y-m-d 00:00:00', mktime(0, 0,0, date('m', $time), 1, date('Y', $time)));
$endTime = date('Y-m-d 23:39:59', mktime(0, 0, 0, date('m', $now), date('t', $now), date('Y', $now)));
} elseif ($q === 8) {// 半年内
$text = '半年内';
$time = strtotime('-5 month', $now);
$beginTime = date('Y-m-d 00:00:00', mktime(0, 0,0, date('m', $time), 1, date('Y', $time)));
$endTime = date('Y-m-d 23:39:59', mktime(0, 0, 0, date('m', $now), date('t', $now), date('Y', $now)));
} elseif ($q === 9) {// 一年内
$text = '一年内';
$beginTime = date('Y-m-d 00:00:00', mktime(0, 0,0, 1, 1, date('Y', $now)));
$endTime = date('Y-m-d 23:39:59', mktime(0, 0, 0, 12, 31, date('Y', $now)));
} elseif ($q === 10) {// 三年内
$text = '三年内';
$time = strtotime('-2 year', $now);
$beginTime = date('Y-m-d 00:00:00', mktime(0, 0, 0, 1, 1, date('Y', $time)));
$endTime = date('Y-m-d 23:39:59', mktime(0, 0, 0, 12, 31, date('Y')));
} echo $text;
echo '<br />';
echo $beginTime;
echo '<br />';
echo $endTime;

原文地址;http://blog.csdn.net/gt219/article/details/53184983

05-02 00:24