mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-30 23:30:05 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@45883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -79,6 +79,17 @@ function current_time( $type, $gmt = 0 ) {
|
||||
return $datetime->format( $type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current time as an object with the timezone from settings.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*
|
||||
* @return DateTimeImmutable Date and time object.
|
||||
*/
|
||||
function current_datetime() {
|
||||
return new DateTimeImmutable( 'now', wp_timezone() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the timezone from current settings as a string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user