Manual:wfTimestamp/ja
Appearance
概要
wfTimestamp() (GlobalFunctions.php の一部) は、MediaWiki タイムスタンプ、UNIX タイムスタンプ、MySQL DATETIME 書式、RFC 2822 書式など、一般的なタイムスタンプ書式間で変換する機能を提供します。
完全な一覧は下記の書式を参照してください。
タイムスタンプは、タイムゾーンなし、または特定の書式で指定された GMT タイムゾーンで出力されます。
データベースにタイムスタンプを挿入する際は、絶対に wfTimestamp() を使用しないでください。 これにより PostgreSQL が破損します (おそらく他の非 MySQL データベースも)。 代わりに $dbw->timestamp() を使用してください
使用法
wfTimestamp( $output_format, $timestamp )
- 引数
$output_formatで指定された書式の文字列型のタイムスタンプを返します。 $output_formatの引数で正しくない書式が渡された場合はMWExceptionをスローします。$timestamp引数で無効または認識できないタイムスタンプが渡された場合、falseを返します。
| 引数 | 既定 | 注記 |
|---|---|---|
$output_format
|
TS_UNIX
|
formats の表に記載されている定数のいずれかである必要があります。 |
$timestamp
|
現在の日時 | 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(); // 1769081699
- Call with one argument to return the current time in the specified format.
echo wfTimestamp( TS_ISO_8601 ); // 2026-01-22T11:34:59Z
- Call with two arguments to return an arbitrary timestamp in the specified format.
タイムスタンプは、wfTimestamp() が出力できる任意の書式であることに注意してください。
$timestamp = 20260159113459;
echo wfTimestamp( TS_ISO_8601, $timestamp ); // 2026-01-22T11:34:59Z
$timestamp = '2026-01-22T11:34:59Z';
echo wfTimestamp( TS_RFC2822, $timestamp ); // Thu, 22 Jan 2026 11:34:59 GMT
書式
| 種類 | 定数 | 書式[1] | 例 | 注記 | ||
|---|---|---|---|---|---|---|
MySQL DATETIME |
TS_DB |
Y-m-d H:i:s |
2026-01-22 11:34:59 | |||
| DB2 | TS_DB2 |
Y-m-d H:i:s |
2026-01-22 11:34:59 | gerrit:50764 で除去されました
| ||
| Exif | TS_EXIF |
Y:m:d H:i:s |
2026:01:22 11:34:59 | Shouldn't ever be used, but is included for completeness. [2] | ||
| ISO 8601 (タイムゾーンなし) | TS_ISO_8601 |
Y-m-d\TH:i:s\Z |
2026-01-22T11:34:59Z | Special:Export および API で使用されます | ||
| ISO 8601 基本 (タイムゾーンなし) | TS_ISO_8601_BASIC |
Ymd\THis\Z |
20260122T113459Z | ResourceLoader で使用されます | ||
| MediaWiki | TS_MW |
YmdHis |
20260122113459 | |||
| Oracle | TS_ORACLE |
d-m-Y H:i:s.000000 |
22-01-2026 11:34:59.000000 | phab:rSVN51500 より前は 'd-M-y h.i.s A' . ' +00:00' でした | ||
| PostgreSQL | TS_POSTGRES |
Y-m-d H:i:s+00 |
2026-01-22 11:34:59+00 | gerrit:459601 より前は 'Y-m-d H:i:s' . ' GMT' でした | ||
| RFC 2822 | TS_RFC2822 |
D, d M Y H:i:s |
Thu, 22 Jan 2026 11:34:59 GMT | For email and HTTP headers | ||
| UNIX time | TS_UNIX |
U |
1769081699 | Number of seconds since 1970-01-01 00:00:00 UTC |
- ↑ Formatting codes per PHP's
date()function. - ↑ 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 http://exif.org/Exif2-2.PDF
関連項目
- wfTimestamp() - source docs