-1

我不明白为什么会这样

echo date('l F y',strtotime('next Tuesday',time())) . "\n";
echo date('l F y',strtotime('next Wednesday',time())) . "\n";
echo date('l F y',strtotime('next Thursday',time())) . "\n";
echo date('l F y',strtotime('next Friday',time())) . "\n";

给我

Tuesday October 12
Wednesday October 12
Thursday October 12
Friday October 12

为什么?

4

4 回答 4

6

您要求它输出星期几,然后是月份,然后是年份的最后两位数字,这就是它正在做的事情。

在此处查看日期格式字符列表及其含义。

于 2012-10-24T06:32:10.440 回答
3

正如@jrdn 所说,这y是一年,所以你得到下周二的年份等。

对于日期使用这个:

echo date('l F d',strtotime('next Tuesday',time())) . "\n";
echo date('l F d',strtotime('next Wednesday',time())) . "\n";
echo date('l F d',strtotime('next Thursday',time())) . "\n";
echo date('l F d',strtotime('next Friday',time())) . "\n";

输出:

Tuesday October 30
Wednesday October 31
Thursday October 25
Friday October 26
于 2012-10-24T06:35:01.967 回答
0

我想如果你添加 d 格式会更清楚

echo date('d l F y',strtotime('next Tuesday',time())) . "\n";
echo date('d l F y',strtotime('next Wednesday',time())) . "\n";
echo date('d l F y',strtotime('next Thursday',time())) . "\n";
echo date('d l F y',strtotime('next Friday',time())) . "\n";

将 o/p

30 Tuesday October 12 // next tuesday date since this week tuesday has already passed
31 Wednesday October 12 // next wed date since this week wed has already passed
25 Thursday October 12 // next thur date since this week thur is yet to pass
26 Friday October 12 // next fri date since this week fri is yet to pass

阅读更多关于date()

于 2012-10-24T06:38:11.793 回答
0

看一下这个?

<?php
$nexTuesday = date('l F y',strtotime('next Tuesday',time())) . "\n";
$nextWednesday = date('l F y',strtotime('next Wednesday',time())) . "\n";
$nextThursday = date('l F y',strtotime('next Thursday',time())) . "\n";
$nextFriday = date('l F y',strtotime('next Friday',time())) . "\n";

//Lets make date to time

$nexTuesday = strtotime($nexTuesday);
$nextWednesday = strtotime($nextWednesday);
$nextThursday = strtotime($nextThursday);
$nextFriday = strtotime($nextFriday);

//If you have need for this, then echo the timestamp as 'l F y' like this:

echo date('l F y',$nextFriday);
?>
于 2012-10-24T06:41:17.933 回答