wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



mysql2date › WordPress Function

Seit0.71
Veraltetn/v
mysql2date ( $format, $date, $translate = true )
Parameter: (3)
  • (string) $format Format of the date to return.
    Erforderlich: Ja
  • (string) $date Date string to convert.
    Erforderlich: Ja
  • (bool) $translate Whether the return date should be translated. Default true.
    Erforderlich: Nein
    Standard: true
Gibt zurück:
  • (string|int|false) Integer if `$format` is 'U' or 'G', string otherwise. False on failure.
Definiert in:
Codex:

Converts given MySQL date string into a different format.

- $format should be a PHP date format string. - 'U' and 'G' formats will return an integer sum of timestamp with timezone offset. - $date is expected to be local time in MySQL format (Y-m-d H:i:s). Historically UTC time could be passed to the function to produce Unix timestamp. If $translate is true then the given date and format string will be passed to wp_date() for translation.


Ähnliche Funktionen: is_date, translate

Quellcode

function mysql2date( $format, $date, $translate = true ) {
	if ( empty( $date ) ) {
		return false;
	}

	$timezone = wp_timezone();
	$datetime = date_create( $date, $timezone );

	if ( false === $datetime ) {
		return false;
	}

	// Returns a sum of timestamp with timezone offset. Ideally should never be used.
	if ( 'G' === $format || 'U' === $format ) {
		return $datetime->getTimestamp() + $datetime->getOffset();
	}

	if ( $translate ) {
		return wp_date( $format, $datetime->getTimestamp(), $timezone );
	}

	return $datetime->format( $format );
}