Languages: English • 日本語 (Add your language)
Returns the blog's current local time in the specified format. There are two named formats: 'mysql' for MySQL/MariaDB's timestamp data type format (i.e. YYYY-MM-DD HH:MM:SS), and 'timestamp' for the Unix timestamp format (i.e. epoch). Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d') since 3.9.0. The optional secondary parameter can be used to retrieve GMT time instead of the blog's local time.
The local time returned is based on the timezone set on the blog's General Settings page, which is UTC by default.
Note that if you are storing the time of an event, current_time( 'timestamp' ) should not be used in lieu of time(), as it returns a Unix timestamp that is incorrectly offset and inaccurate. Unix timestamps are always in UTC and do not have any other timezone attached. Should the site owner change the timezone of the WordPress installation at any time, stored timestamps that are offset using current_time( 'timestamp' ) will be incorrect. Instead of using current_time( 'timestamp' ), which is no longer recommended, use time() and store it unmodified. Then upon output to the screen, convert it to the user's timezone by passing the timezone to your visualization method using PHP's DateTime class.
<?php $time = current_time( $type, $gmt = 0 ); ?>
If the first parameter is 'mysql', the function returns a date-time string. If the first parameter is 'timestamp', the function returns a double value equal to the number of seconds since Jan. 1, 1970. When strict data typing is necessary, take note that the PHP time() function, which current_time() replaces, returns an integer value, so consider using (int) current_time( 'timestamp' ) instead.
As of version 3.9, any other value for the first parameter will be used as the format for the time. For example, current_time( 'Y-m-d' ) will return something like '2014-04-14'.
If the optional second parameter is 1, the value returned represents the current GMT time. If 0 or no second parameter are set, the value returned represents the local time for the timezone declared in the blog's Timezone setting on the General Settings page.
This example gets the current time and assigns the parameters to variables.
<?php $blogtime = current_time( 'mysql' ); list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime ); ?>
2005-08-05 10:41:13
<?php echo "current_time( 'mysql' ) returns local site time: " . current_time( 'mysql' ) . '<br />'; echo "current_time( 'mysql', 1 ) returns GMT: " . current_time( 'mysql', 1 ) . '<br />'; echo "current_time( 'timestamp' ) returns local site time: " . date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) ); echo "current_time( 'timestamp', 1 ) returns GMT: " . date( 'Y-m-d H:i:s', current_time( 'timestamp', 1 ) ); ?>
current_time() is located in wp-includes/functions.php
Time Functions: current_time(), human_time_diff(), the_time(), get_the_time(), comment_time()