{"id":9602479,"date":"2017-10-19T18:04:59","date_gmt":"2017-10-19T18:04:59","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/using-wordpresss-date-time-format-settings\/"},"modified":"2017-10-19T18:04:59","modified_gmt":"2017-10-19T18:04:59","slug":"using-wordpresss-date-time-format-settings","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/using-wordpresss-date-time-format-settings\/","title":{"rendered":"Using WordPress&#8217;s date\/time format settings"},"content":{"rendered":"<p>I have a plugin that relies on CMB2.<\/p>\n<p>That plugin does a lot of stuff with dates, and I have found that users are really picky about date\/time formats. My plugin grabs the date\/time formats from WordPress&#8217;s general settings, and uses those formats everywhere.<\/p>\n<p>However, I cannot get those settings to work within a metabox with a text_datetime_timestamp field.  If I add a &#8216;date_format&#8217; parameter to that field, the field data will not save.  Additionally, if the date format is set to &#8216;MM j, yy&#8217;, the format is displayed as &#8216;MayMay 05, 1717&#8217; instead of &#8216;May 05, 2017&#8217;.<\/p>\n<p>In other words, if I use this code:<\/p>\n<pre><code>$shift_meta-&gt;add_field( array(\n    &#039;name&#039; =&gt; __( &#039;Scheduled Start Date\/Time&#039;, &#039;employee-scheduler&#039; ),\n    &#039;id&#039;   =&gt; $prefix . &#039;shift_start&#039;,\n    &#039;type&#039; =&gt; &#039;text_datetime_timestamp&#039;,\n    &#039;date_format&#039; =&gt; &#039;MM j, yy&#039;\n ) );<\/code><\/pre>\n<p>the date will not save, and the format is displayed incorrectly.<\/p>\n<p>Other people have reported these issues:<br \/>\nhttps:\/\/github.com\/CMB2\/CMB2\/issues\/765<br \/>\nhttps:\/\/github.com\/CMB2\/CMB2\/issues\/646<\/p>\n","protected":false},"template":"","class_list":["post-9602479","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9602479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9602479\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=9602479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}