Retrieves the current time based on specified type.
Description
<ul> <li>The 'mysql' type will return the time in the format for MySQL DATETIME field.</li> <li>The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp and timezone offset, depending on $gmt.</li> <li>Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').</li> </ul> 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.
Parameters
$typestring
Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U', or PHP date format string (e.g. 'Y-m-d').
$gmtbooloptional
Whether to use GMT timezone. Default false.Default: false
Return
int|string
Integer if $type is 'timestamp' or 'U', string otherwise.
Uses · 4
get_option()Retrieves an option value based on an option name.
wp_timezone()Retrieves the timezone of the site as a `DateTimeZone` object.
78functioncurrent_time($type,$gmt=false){79// Don't use non-GMT timestamp, unless you know the difference and really need to.80if('timestamp'===$type||'U'===$type){81return$gmt?time():time()+(int)((float)get_option('gmt_offset')*HOUR_IN_SECONDS);82}8384if('mysql'===$type){85$type='Y-m-d H:i:s';86}8788$timezone=$gmt?newDateTimeZone('UTC'):wp_timezone();89$datetime=newDateTime('now',$timezone);9091return$datetime->format($type);92}
History
Introduced in 1.0.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Parameter $gmt retyped from int|bool to bool.verified against source
5.3.0
Now returns an integer if $type is 'U'. Previously a string was returned.from the docblock
1.0.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.