Jump to navigation Jump to search
This page is a translated version of the page Manual:WfTimestamp and the translation is 38% complete.
Other languages:
English • ‎বাংলা • ‎日本語


wfTimestamp() (part of GlobalFunctions.php) provides functionality to convert between common timestamp formats, including MediaWiki timestamps, UNIX timestamps, MySQL DATETIME format, RFC 2822 format and more. See formats below for a full list.

タイムスタンプは、タイムゾーンなし、または特定の書式で指定された GMT タイムゾーンで出力されます。

Never use wfTimestamp() when inserting a timestamp into the database. This will break in Postgres and possibly other non-MySQL databases. Instead use $dbw->timestamp()


wfTimestamp( $output_format, $timestamp )

  • 引数 $output_format で指定された書式の文字列型のタイムスタンプを返します。
  • Throws MWException if an incorrect formats is passed via the $output_format argument.
  • $timestamp 引数で無効または認識できないタイムスタンプが渡された場合、false を返します。

Argument Default Notes
$output_format TS_UNIX Must be one of the constants listed in the formats table.
$timestamp The current time Should be a literal timestamp (e.g. 2010-12-03 22:07:25. Any format listed in the formats table can be used.

Call with no arguments to return the current time in UNIX time format.
echo wfTimestamp(); // 291414045
Call with one argument to return the current time in the specified format.
echo wfTimestamp( TS_ISO_8601 ); // 2010-12-03T22:09:28Z
Call with two arguments to return an arbitrary timestamp in the specified format.

タイムスタンプは、wfTimestamp() が出力できる任意の書式であることに注意してください。

$timestamp = 20100809003006;
echo wfTimestamp( TS_ISO_8601, $timestamp ); // 2010-08-09T00:30:06Z

$timestamp = '2010-08-09T00:30:06Z';
echo wfTimestamp( TS_RFC2822, $timestamp ); // Mon, 09 Aug 2010 00:30:06 GMT


Type Constant Format[1] Example Notes
MySQL DATETIME TS_DB Y-m-d H:i:s 2021-06-16 04:33:43
DB2 TS_DB2 Y-m-d H:i:s 2021-06-16 04:33:43
Exif TS_EXIF Y:m:d H:i:s 2021:06:16 04:33:43 Shouldn't ever be used, but is included for completeness. [2]
ISO 8601 (no timezone) TS_ISO_8601 Y-m-d\TH:i:s\Z 2021-06-16T04:33:43Z Used by Special:Export and the API
ISO 8601 basic (no timezone) TS_ISO_8601_BASIC Ymd\THis\Z 20210616T043343Z Used by ResourceLoader
MediaWiki TS_MW YmdHis 20210616043343
Oracle TS_ORACLE d-m-Y H:i:s.000000 16-06-2021 04:33:43.000000 Was 'd-M-y h.i.s A' . ' +00:00' before r51500
PostgreSQL TS_POSTGRES Y-m-d H:i:s 2021-06-16 04:33:43 GMT
RFC 2822 TS_RFC2822 D, d M Y H:i:s 水, 16 6月 2021 04:33:43 GMT For email and HTTP headers
UNIX time TS_UNIX U 1623818023 Number of seconds since 1970-01-01 00:00:00 UTC
  1. Formatting codes per PHP's date() function.
  2. Documented on page 28 (for the DateTime tag) and page 36 (for the DateTimeOriginal and DateTimeDigitized tags) of the Exif 2.2 specification. Download the specification at

See also