直接看代码就知道啥意思了!
<?php
echo "今天凌晨的时间戳:" . strtotime(date(
"Y-m-d")) . PHP_EOL;
echo "一天后:" . date(
"Y-m-d", strtotime(
"+1 day")) . PHP_EOL;
echo "一周后:" . date(
"Y-m-d", strtotime(
"+1 week")) . PHP_EOL;
echo "一周零两天四小时两秒后:" . date(
"Y-m-d G:H:s", strtotime(
"+1 week 2 days 4 hours 2 seconds")) . PHP_EOL;
echo "下个星期四:" . date(
"Y-m-d", strtotime(
"next Thursday")) . PHP_EOL;
echo "上个周一:" . date(
"Y-m-d", strtotime(
"last Monday")) . PHP_EOL;
echo "一个月前:" . date(
"Y-m-d", strtotime(
"last month")) . PHP_EOL;
echo "一个月后:" . date(
"Y-m-d", strtotime(
"+1 month")) . PHP_EOL;
echo "十年后:" . date(
"Y-m-d", strtotime(
"+10 year")) . PHP_EOL;
echo strtotime(
"now"),
"\n";
echo strtotime(
"+0 day"),
"\n";
echo strtotime(
"10 September 2000"),
"\n";
echo strtotime(
"+1 day"),
"\n";
echo strtotime(
"+1 week"),
"\n";
echo strtotime(
"+1 week 2 days 4 hours 2 seconds"),
"\n";
echo strtotime(
"next Thursday"),
"\n";
echo strtotime(
"last Monday"),
"\n";
print date(
'Y-m-d', strtotime(
'-1 day')) . PHP_EOL;
print date(
'Y-m-d', strtotime(
'-1 week')) . PHP_EOL;
print date(
'Y-m-d', strtotime(
'-1 month')) . PHP_EOL;
print date(
'Y-m-d', strtotime(
'-1 year')) . PHP_EOL;
怎么样,是不是很有用处!
看看效果:
补充–2018.3.19
$data = date(
'Y-m-d H:i:s', strtotime(
'-1 monday'));
$data = date(
'Y-m-d H:i:s', strtotime(
'+2 monday'));
function birthday2($birthday)
{
list(
$year,
$month,
$day) = explode(
"-",
$birthday);
$year_diff = date(
"Y") -
$year;
$month_diff = date(
"m") -
$month;
$day_diff = date(
"d") -
$day;
if (
$day_diff <
0 ||
$month_diff <
0) {
$year_diff--;
}
return $year_diff;
}
转载请注明原文地址: https://www.6miu.com/read-31503.html