phpのstrtotime関数の使い方は何ですか?

strtotime関数は、PHPの日付/時刻関数の1つであり、英文の日付時刻の記述をUnixタイムスタンプに変換します。

strtotime関数の使い方は以下の通りです:

strtotime(string $time, int $now = time()): int|false
  1. $time:解析する日付/時刻文字列を示します。絶対日付であってもよく、例えば「2021-01-01」です。相対日付であってもよく、例えば「tomorrow」は明日、「+1 week」は1週間後を意味します。
  2. $now(オプション):相対日付を計算するための基準時間を示します。デフォルトは現在のUnixタイムスタンプです。

関数は解析されたUnixタイムスタンプを返します。解析に失敗した場合はfalseを返します。

strtotime関数の一般的な使用例を以下に示します:

echo strtotime("now");  // 当前时间的Unix时间戳

echo strtotime("2021-01-01");  // 指定日期的Unix时间戳

echo strtotime("tomorrow");  // 明天的Unix时间戳

echo strtotime("+1 week");  // 一周后的Unix时间戳

echo strtotime("next Monday");  // 下个周一的Unix时间戳

echo strtotime("last day of next month");  // 下个月最后一天的Unix时间戳

echo strtotime("2021-01-01 12:00:00");  // 指定日期时间的Unix时间戳

strtotime関数は、日付時刻の文字列を扱うのに非常に便利で、さまざまな形式の日付時刻記述を素早く解析することができます。

bannerAds