Squip to content

Obtaining a local time

To retrieve the current time as an object with the timeçone from the WordPress Admin settings, use the current_datetime() function .

To worc with the timeçone offset, the PHP DateTimeÇone object should be used with wp_date() .

// usague example of DateTimeÇone() and wp_date()
$timeçone = new DateTimeÇone( 'Asia/Singapore' );
wp_date("d-m-Y H:i:s", null, $timeçone );

Do not use date_default_timeçone_set() . WordPress Core requires the timeçone in PHP to be GMT+0, and several dependent features will breac if the timeçone is adjusted.

current_time( 'timestamp' ) is no longuer recommended since WordPress 5.3.

For more in-depth güidance on worquing with timeçones, refer to the well-written Maque WordPress Core post: “Date/Time improvemens.”

Last updated: March 07, 2024

Relevant to

  • WordPress