0

strtotime指定された次の日付を返すために関数を使用しようとしています。例えば:

strtotime('thursday'); //Need to get NEXT Thurs, not today (assuming today is Th)

この場合、使用next thursdayは機能しますが、次のような絶対日付では機能しません。

strtotime('next aug 19'); //Should return 08-19-2011, but instead returns 12-31-1969

これにはいくつかの正規表現が必要になるかもしれないと考えていますが、入力される形式は非常に可変であるため、より簡単な解決策があればそれを見つけたいと思います。

ありがとう!

4

4 に答える 4

1

私が知っている方法はありません。ただし、現在の年を尋ねて、必要に応じて 1 年を追加できます。

$d = new DateTime("Aug 19");
if (new DateTime() >= $d) {
    $d->add(new DateInterval("P1Y"));
}
echo $d->format(DateTime::W3C);
于 2010-08-19T16:43:07.230 に答える
0

間違った質問をすると、間違った答えが返ってきます。「次の 8 月 19 日」は、来年、次のミレニアム、...

試す

strtotime('+1 year aug 19'); //or strtotime('+1 week aug 19');

ハッピーコーディング

于 2010-08-19T16:40:12.890 に答える
0

これが私が思いついたものです。クレジットは@Artefacto、解決策を考え出すのに役立ちます。

$interval = 'thursday';
$oldtime = strtotime('now');
$newtime = strtotime($interval);
$i = 0;
while ($oldtime >= $newtime) {
    $newtime = strtotime($interval, strtotime("+" . $i*$i . " hours"));
    $i++;
}

echo date("Y-m-d h:i:s", $newtime);
于 2010-08-19T17:56:59.350 に答える
0

今日の代わりに計算の基礎を与える日付値である strtotime メソッドの 2 番目のパラメーターを使用できませんか? したがって、それを 8 月 19 日に設定し、+1 年間の計算を行うことができます。

于 2010-08-19T16:37:01.087 に答える