[wp-trac] [WordPress Trac] #48976: Current_time
WordPress Trac
noreply at wordpress.org
Sun Dec 15 02:43:34 UTC 2019
#48976: Current_time
--------------------------+-----------------------------
Reporter: autotutorial | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Revisions | Version: 5.3
Severity: normal | Keywords: needs-codex
Focuses: |
--------------------------+-----------------------------
{{{#!php
<?php
function current_time( $type, $gmt = 0 ) {
// Don't use non-GMT timestamp, unless you know the difference and
really need to.
if ( 'mysql' === $type ) {
$type = 'Y-m-d H:i:s';
}
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : new
DateTimeZone(wp_timezone());
$datetime = new DateTime( 'now', $timezone );
if ( 'timestamp' === $type || 'U' === $type ) {
//for UTC offset is 0
return time()+$datetime->getOffset();
}
return $datetime->format( $type );
}
}}}
Add correct DateTimeZone for $gmt 0 and $timestamp or U now have your
appropiate offset.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48976>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list