WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/23/2019 01:11:22 AM (4 months ago)
Author:
SergeyBiryukov
Message:

Date/Time: Introduce current_datetime() for better time operations.

Returning a DateTimeImmutable representation of the current moment in time, this allows for a more flexible and reliable use than current_time() provides.

Props Rarst.
Fixes #47464.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r45882 r45883  
    7878
    7979    return $datetime->format( $type );
     80}
     81
     82/**
     83 * Retrieves the current time as an object with the timezone from settings.
     84 *
     85 * @since 5.3.0
     86 *
     87 * @return DateTimeImmutable Date and time object.
     88 */
     89function current_datetime() {
     90    return new DateTimeImmutable( 'now', wp_timezone() );
    8091}
    8192
Note: See TracChangeset for help on using the changeset viewer.