Useful Time Function in WordPress

In WordPress, there is a function named current_time() used to deal with the current local time. If you set timestamp as the first parameter, it will return the current timestamp use seconds. It also support PHP date format strings. see https://www.php.net/manual/en/datetime.format.php

Here is some useful PHP date format short string

  • Y - Year(4 digits)
  • y - Year(2 digits)
  • m - Month(01-12)
  • n - Month(1-12)
  • d - Date(01-31)
  • j - Date(1-31)
  • H - Hour(00-23)
  • h - Hour(01-12)
  • G - Hour(1-23)
  • g - Hour(1-12)
  • i - Minute(01-59)
  • s - Second(01-59)

Sample

1
current_time('Y-m-d H:i:s')