Un motore di ricerca WordPress per sviluppatori e autori di temi



mysql2date ›

Da0.71
Deprecaton/a
mysql2date ( $format, $date, $translate = true )
Parametri: (3)
  • (string) $format Format of the date to return.
    Richiesto:
  • (string) $date Date string to convert.
    Richiesto:
  • (bool) $translate Whether the return date should be translated. Default true.
    Richiesto: No
    Default: true
Ritorna:
  • (string|int|false) Formatted date string or sum of Unix timestamp and timezone offset. False on failure.
Definito a:
Codex:

Convert given MySQL date string into a different format.

$format should be a PHP date format string. 'U' and 'G' formats will return a 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.



Funzioni correlate: is_date, translate, _wp_mysql_week

Sorgenti

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

	$datetime = date_create( $date, wp_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() );
	}

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