current_time

Home » Functions » current_time

The current_time function is a built-in WordPress function that returns the current local time in a specific format. This function can be used to display the current time in a specific timezone or format on your WordPress site.

The current_time function takes two parameters: $format and $gmt. The $format parameter specifies the format for the returned time, while the $gmt parameter specifies whether the returned time should be based on GMT time or not.

Here’s an example usage code:

$current_time = current_time( 'Y-m-d H:i:s', true );
echo 'The current time is ' . $current_time . ' (GMT time)';

In this example, the current_time function is used to retrieve the current time in the ‘Y-m-d H:i:s’ format and based on GMT time. The returned time is then stored in the $current_time variable and displayed on the front end using an echo statement.

Overall, the current_time function is a useful tool for displaying the current time in a specific format and timezone on your WordPress site.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.