CakeFest 2024: The Official CakePHP Conference

gmdate

(PHP 4, PHP 5, PHP 7, PHP 8)

gmdateGMT/UTC の日付/時刻を書式化する

説明

gmdate(string $format, ?int $timestamp = null): string

date() 関数と同じですが、返される時刻が グリニッジ標準時 (GMT) であるところが異なります。

パラメータ

format

出力される文字列の書式。date() 関数の書式オプションを参照ください。

timestamp

オプションのパラメータ timestamp は、 int 型の Unix タイムスタンプです。 timestamp が指定されなかったり、null だった場合のデフォルト値は、 現在の時刻です。言い換えると、デフォルトは time() の返り値となります。

戻り値

日付を表す文字列を返します。

変更履歴

バージョン 説明
8.0.0 timestamp は、nullable になりました。

例1 gmdate() の例

フィンランド (GMT +0200) で実行した場合、一行目の出力は "Jan 01 1998 00:00:00"、二行目の出力は "Dec 31 1997 22:00:00" となります。

<?php
echo date("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
echo
gmdate("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
?>

参考

add a note

User Contributed Notes 1 note

up
0
bruno dot dasilva at odaseva dot com
7 days ago
with PHP7.4 (and probably below), when the 2d parameter $timestamp is null, then the date will be based on timestamp "0" (1970-01-01T00:00:00)
To Top