{"id":9711,"date":"2022-06-22T18:17:50","date_gmt":"2022-06-22T08:17:50","guid":{"rendered":"https:\/\/wpdevdesign.wpengine.com\/?p=9711"},"modified":"2023-03-08T09:33:32","modified_gmt":"2023-03-07T22:33:32","slug":"date-and-time-in-wordpress-dev-notes","status":"publish","type":"post","link":"https:\/\/wpdevdesign.com\/date-and-time-in-wordpress-dev-notes\/","title":{"rendered":"Date and Time in WordPress &#8211; Dev Notes"},"content":{"rendered":"<div class=\"mp_wrapper\">\n  <div class=\"mepr-unauthorized-excerpt\">\n    <p>In this article, I share the notes I put together as I was going through <a rel=\"noreferrer noopener\" href=\"https:\/\/make.wordpress.org\/core\/2019\/09\/23\/date-time-improvements-wp-5-3\/\" target=\"_blank\">Date\/Time component improvements in WordPress 5.3<\/a>.<\/p>\n<p>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.<\/p>\n<p>What's covered:<\/p>\n<ul class=\"wp-block-list\">\n<li>Timezone string<\/li>\n<li>Timezone of the site as a DateTimeZone object<\/li>\n<li>Current time as Unix timestamp<\/li>\n<li>Current time as a Date and time object (instance of DateTimeImmutable class) using the site's timezone<\/li>\n<li>Current date and time in the specified format taking into account the site's timezone setting<\/li>\n<li>Time since the current post was published in human-readable format<\/li>\n<li>Date and Time Comparison<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Timezone string<\/h2>\n<p>Might return Region\/Location string or \u00b1NN:NN offset.<\/p>\n  <\/div>\n  <div class=\"mepr-unauthorized-message\">\n    <p>This is a premium members-only content.<\/p>\n<p>To view the rest of the content, please <a title=\"Membership\" href=\"https:\/\/wpdevdesign.com\/membership\/\">sign up for membership ($47\/month or $599 one-time)<\/a>.<\/p>\n<p>Already a member? Log in below or <a href=\"https:\/\/wpdevdesign.com\/login\/\">here<\/a>.<\/p>\n  <\/div>\n  <div class=\"mepr-login-form-wrap\">\n            \n<div class=\"mp_wrapper mp_login_form\">\n                  <!-- mp-login-form-start -->     <form name=\"mepr_loginform\" id=\"mepr_loginform\" class=\"mepr-form\" action=\"https:\/\/wpdevdesign.com\/login\/\" method=\"post\">\n            <div class=\"mp-form-row mepr_username\">\n        <div class=\"mp-form-label\">\n                              <label for=\"user_login\">Username<\/label>\n        <\/div>\n        <input type=\"text\" name=\"log\" id=\"user_login\" value=\"\" \/>\n      <\/div>\n      <div class=\"mp-form-row mepr_password\">\n        <div class=\"mp-form-label\">\n          <label for=\"user_pass\">Password<\/label>\n          <div class=\"mp-hide-pw\">\n            <input type=\"password\" name=\"pwd\" id=\"user_pass\" value=\"\" \/>\n            <button type=\"button\" class=\"button mp-hide-pw hide-if-no-js\" data-toggle=\"0\" aria-label=\"Show password\">\n              <span class=\"dashicons dashicons-visibility\" aria-hidden=\"true\"><\/span>\n            <\/button>\n          <\/div>\n        <\/div>\n      <\/div>\n            <div>\n        <label><input name=\"rememberme\" type=\"checkbox\" id=\"rememberme\" value=\"forever\" \/> Remember Me<\/label>\n      <\/div>\n      <div class=\"mp-spacer\">&nbsp;<\/div>\n      <div class=\"submit\">\n        <input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" class=\"button-primary mepr-share-button \" value=\"Log In\" \/>\n        <input type=\"hidden\" name=\"redirect_to\" value=\"\/wp-json\/wp\/v2\/posts\/9711\" \/>\n        <input type=\"hidden\" name=\"mepr_process_login_form\" value=\"true\" \/>\n        <input type=\"hidden\" name=\"mepr_is_login_page\" value=\"false\" \/>\n      <\/div>\n    <\/form>\n    <div class=\"mp-spacer\">&nbsp;<\/div>\n    <div class=\"mepr-login-actions\">\n        <a\n          href=\"https:\/\/wpdevdesign.com\/login\/?action=forgot_password\"\n          title=\"Click here to reset your password\"\n        >\n          Forgot Password        <\/a>\n    <\/div>\n\n      \n    <!-- mp-login-form-end --> \n  <\/div>\n      <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":9717,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"Using WordPress Date\/Time: Get Current Date &amp; Time, Compare User-Input Times","_seopress_titles_desc":"Learn how to write custom code to get current date, time and timezone settings in WordPress in this detailed article.","_seopress_robots_index":"","sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"footnotes":""},"categories":[52,20],"tags":[506],"class_list":["post-9711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-premium","category-wordpress","tag-date-and-time"],"acf":[],"featured_image_src":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2022\/06\/date-time-wordpress-dev-notes-600x400.png","featured_image_src_square":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2022\/06\/date-time-wordpress-dev-notes-600x600.png","author_info":{"display_name":"Sridhar Katakam","author_link":"https:\/\/wpdevdesign.com\/author\/srikat\/"},"_links":{"self":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/9711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/comments?post=9711"}],"version-history":[{"count":0,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/9711\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media\/9717"}],"wp:attachment":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media?parent=9711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/categories?post=9711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/tags?post=9711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}