Manual:WfTimestamp/de

Überblick

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.

Timestamps will be output without a timezone or in the GMT timezone, as specified by the particular format.

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

Verwendung

wfTimestamp( $output_format, $timestamp )
  • Returns a timestamp of type string in the format specified by the $output_format argument.
  • Throws MWException if an incorrect formats is passed via the $output_format argument.
  • Returns false if an invalid or unrecognized timestamp is passed via the $timestamp argument.
Argument Default Anmerkungen
$output_format TS_UNIX Must be one of the constants listed in the formats table.
$timestamp Die aktuelle Zeit 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(); // 1752388401

Call with one argument to return the current time in the specified format.

echo wfTimestamp( TS_ISO_8601 ); // 2025-07-13T06:33:21Z

Call with two arguments to return an arbitrary timestamp in the specified format.

Note that the timestamp can be in any format that wfTimestamp() can output.

$timestamp = 20250721063321; echo wfTimestamp( TS_ISO_8601, $timestamp ); // 2025-07-13T06:33:21Z $timestamp = '2025-07-13T06:33:21Z'; echo wfTimestamp( TS_RFC2822, $timestamp ); // Sun, 13 Jul 2025 06:33:21 GMT

Formate

Typ Constant Format[1] Beispiel Anmerkungen
MySQL DATETIMETS_DBY-m-d H:i:s2025-07-13 06:33:21
DB2TS_DB2Y-m-d H:i:s2025-07-13 06:33:21 Entfernt in gerrit:50764
MediaWiki Versions:
1.15 1.20
ExifTS_EXIFY:m:d H:i:s2025:07:13 06:33:21 Sollte nie verwendet werden, aber ist der Vollständigkeit halber enthalten. [2]
ISO 8601 (keine Zeitzone)TS_ISO_8601Y-m-d\TH:i:s\Z2025-07-13T06:33:21Z Verwendet von Special:Export und der API
ISO 8601 basic (no timezone)TS_ISO_8601_BASICYmd\THis\Z20250713T063321Z Verwendet von ResourceLoader
MediaWikiTS_MWYmdHis20250713063321
OracleTS_ORACLEd-m-Y H:i:s.00000013-07-2025 06:33:21.000000 War 'd-M-y h.i.s A' . ' +00:00' vor phab:rSVN51500
PostgreSQLTS_POSTGRESY-m-d H:i:s+002025-07-13 06:33:21+00 War 'Y-m-d H:i:s' . ' GMT' vor gerrit:459601
RFC 2822TS_RFC2822D, d M Y H:i:sSun, 13 Jul 2025 06:33:21 GMT For email and HTTP headers
UNIX timeTS_UNIXU1752388401 Nummer an Sekunden seit 1970-01-01 00:00:00 UTC
  1. Formatting codes per PHP's date() function.
  2. Dokumentiert auf Seite 28 (Für den DateTime-Tag) und Seite 36 (für die DateTimeOriginal- und DateTimeDigitized-Tags) der Exif 2.2-Spezifikation. Lade die Spezifikation unter http://exif.org/Exif2-2.PDF herunter

Siehe auch