I\'m building a custom theme and plugin for WordPress and noticed that calls to date_default_timezone_get()
return \"UTC\" even though:
Yes, WordPress does work in UTC internally so the values you get from PHP’s date()
, time()
, etc. functions will be in UTC as well. You could wrap these in calls to date_default_timezone_set()
but that gets messy.
It's generally easier to use WordPress’s built-in current_time() function.
It can return a formatted date (like you would get using PHP’s date()
function) or a timestamp (like you would get by calling PHP’s time()
function). A returned time value can be used to seed PHP's other date/time functions. By default current_time()
returns values for the local timezone.
NOTE: Do not switch to your local timezone using date_default_timezone_set()
before calling current_time()
or you will get bad values from it.