12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Jun 22, 2022

Date and Time in WordPress – Dev Notes

Sridhar Katakam

In this article, I share the notes I put together as I was going through Date/Time component improvements in WordPress 5.3.

This will be useful for those that want to write custom code for getting the current date and time in the timezone set in WP settings, checking user-input time against the current time to determine if that was in the past or in the future etc.

What's covered:

  • Timezone string
  • Timezone of the site as a DateTimeZone object
  • Current time as Unix timestamp
  • Current time as a Date and time object (instance of DateTimeImmutable class) using the site's timezone
  • Current date and time in the specified format taking into account the site's timezone setting
  • Time since the current post was published in human-readable format
  • Date and Time Comparison

Timezone string

Might return Region/Location string or ±NN:NN offset.

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.