wp_date example

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 );
}

/** * Retrieves the current time based on specified type. * * - The 'mysql' type will return the time in the format for MySQL DATETIME field. * - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp * and timezone offset, depending on `$gmt`. * - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d'). * * If `$gmt` is a truthy value then both types will use GMT time, otherwise the * output is adjusted with the GMT offset for the site. * * @since 1.0.0 * @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned. * * @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U', * or PHP date format string (e.g. 'Y-m-d'). * @param int|bool $gmt Optional. Whether to use GMT timezone. Default false. * @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise. */
return false;
    }

    if ( 'U' === $format || 'G' === $format ) {
        $time = $datetime->getTimestamp();

        // Returns a sum of timestamp with timezone offset. Ideally should never be used.         if ( ! $gmt ) {
            $time += $datetime->getOffset();
        }
    } elseif ( $translate ) {
        $time = wp_date( $format$datetime->getTimestamp()$gmt ? new DateTimeZone( 'UTC' ) : null );
    } else {
        if ( $gmt ) {
            $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
        }

        $time = $datetime->format( $format );
    }

    /** * Filters the localized time a post was written. * * @since 2.6.0 * * @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. * @param string $format Format to use for retrieving the time the post was written. * Accepts 'G', 'U', or PHP date format. * @param bool $gmt Whether to retrieve the GMT time. */
        $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
        $info['wp-server']['fields']['current'] = array(
            'label' => __( 'Current time' ),
            'value' => $date->format( DateTime::ATOM ),
        );
        $info['wp-server']['fields']['utc-time'] = array(
            'label' => __( 'Current UTC time' ),
            'value' => $date->format( DateTime::RFC850 ),
        );
        $info['wp-server']['fields']['server-time'] = array(
            'label' => __( 'Current Server time' ),
            'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ),
        );

        // Populate the database debug fields.         if ( is_resource( $wpdb->dbh ) ) {
            // Old mysql extension.             $extension = 'mysql';
        } elseif ( is_object( $wpdb->dbh ) ) {
            // mysqli or PDO.             $extension = get_class( $wpdb->dbh );
        } else {
            // Unknown sql extension.
// 0 index is the state at current time, 1 index is the next transition, if any.         if ( ! empty( $transitions[1] ) ) {
            echo ' ';
            $message = $transitions[1]['isdst'] ?
                /* translators: %s: Date and time. */
                __( 'Daylight saving time begins on: %s.' ) :
                /* translators: %s: Date and time. */
                __( 'Standard time begins on: %s.' );
            printf(
                $message,
                '<code>' . wp_date( __( 'F j, Y' ) . ' ' . __( 'g:i a' )$transitions[1]['ts'] ) . '</code>'
            );
        } else {
            _e( 'This timezone does not observe daylight saving time.' );
        }
    }
    ?> </span> </p> <?php endif; ?> </td> </tr> <tr> <th scope="row">
Home | Imprint | This part of the site doesn't use cookies.