{"id":10851332,"date":"2018-11-06T03:52:35","date_gmt":"2018-11-06T03:52:35","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=helphub_article&#038;p=10851332"},"modified":"2025-07-20T14:48:59","modified_gmt":"2025-07-20T14:48:59","slug":"customize-date-and-time-format","status":"publish","type":"helphub_article","link":"https:\/\/wordpress.org\/documentation\/article\/customize-date-and-time-format\/","title":{"rendered":"Customize date and time format"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Customizing the Time and Date Format<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Certain WordPress tag functions are used to display or return date and time information; <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/the_date\/\">the_date()<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/the_time\/\">the_time()<\/a> are examples of this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, these functions will display or return date and time in format as it is set in <a href=\"\/support\/article\/administration-screens\/\">Administration<\/a> &gt; <a href=\"\/support\/article\/administration-screens\/#general\">Settings<\/a> &gt; <a href=\"\/support\/article\/settings-general-screen\/\">General<\/a>. This is the place where customizing format for Date and Time will take effect throughout the whole WordPress installation.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"372\" src=\"https:\/\/wordpress.org\/documentation\/files\/2018\/11\/time-and-date-settings.png\" alt=\"Dashoboad &gt; Settings &gt; General\" class=\"wp-image-10851337\" srcset=\"https:\/\/wordpress.org\/documentation\/files\/2018\/11\/time-and-date-settings.png 883w, https:\/\/wordpress.org\/documentation\/files\/2018\/11\/time-and-date-settings-300x126.png 300w, https:\/\/wordpress.org\/documentation\/files\/2018\/11\/time-and-date-settings-768x324.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><figcaption class=\"wp-element-caption\">Formatting Date and Time<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Notice the string of characters next to each Date and Time formatting in screenshot. This string is called a <strong>format string<\/strong>. Each letter represents specific part of Date or Time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the format string:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">l, F j, Y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">creates a date that look like this (note that commas are read literally):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Friday, September 24, 2004<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what each format character in the string above represents:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>l<\/code> = Full name for day of the week (lower-case L).<\/li>\n\n\n\n<li><code>F<\/code> = Full name for the month.<\/li>\n\n\n\n<li><code>j<\/code> = The day of the month.<\/li>\n\n\n\n<li><code>Y<\/code> = The year in 4 digits. (lower-case y gives the year&#8217;s last 2 digits)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Format characters are standardized and globally used in <a href=\"https:\/\/codex.wordpress.org\/Glossary#PHP\">PHP<\/a> programming language. As WordPress is written in PHP programming language you can use the table of Date and Time format characters <a href=\"http:\/\/php.net\/date\">directly from the PHP website<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a table of some of the more useful items found there:<\/p>\n\n\n\n<table>\n<tbody>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Day of Month<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>d<\/code><\/td>\n<td style=\"width:55%\">Numeric, with leading zeros<\/td>\n<td style=\"width:45%\">01\u201331<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>j<\/code><\/td>\n<td>Numeric, without leading zeros<\/td>\n<td>1\u201331<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>S<\/code><\/td>\n<td>The English suffix for the day of the month<\/td>\n<td>st, nd or th in the 1st, 2nd or 15th.<\/td>\n<\/tr>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Weekday<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>l<\/code><\/td>\n<td>Full name &nbsp;(lowercase \u2018L\u2019)<\/td>\n<td>Sunday \u2013 Saturday<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>D<\/code><\/td>\n<td>Three letter name<\/td>\n<td>Mon \u2013 Sun<\/td>\n<\/tr>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Month<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>m<\/code><\/td>\n<td>Numeric, with leading zeros<\/td>\n<td>01\u201312<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>n<\/code><\/td>\n<td>Numeric, without leading zeros<\/td>\n<td>1\u201312<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>F<\/code><\/td>\n<td>Textual full<\/td>\n<td>January \u2013 December<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>M<\/code><\/td>\n<td>Textual three letters<\/td>\n<td>Jan \u2013 Dec<\/td>\n<\/tr>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Year<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>Y<\/code><\/td>\n<td>Numeric, 4 digits<\/td>\n<td>Eg., 1999, 2003<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>y<\/code><\/td>\n<td>Numeric, 2 digits<\/td>\n<td>Eg., 99, 03<\/td>\n<\/tr>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Time<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>a<\/code><\/td>\n<td>Lowercase<\/td>\n<td>am, pm<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>A<\/code><\/td>\n<td>Uppercase<\/td>\n<td>AM, PM<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>g<\/code><\/td>\n<td>Hour, 12-hour, without leading zeros<\/td>\n<td>1\u201312<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>h<\/code><\/td>\n<td>Hour, 12-hour, with leading zeros<\/td>\n<td>01\u201312<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>G<\/code><\/td>\n<td>Hour, 24-hour, without leading zeros<\/td>\n<td>0-23<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>H<\/code><\/td>\n<td>Hour, 24-hour, with leading zeros<\/td>\n<td>00-23<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>i<\/code><\/td>\n<td>Minutes, with leading zeros<\/td>\n<td>00-59<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>s<\/code><\/td>\n<td>Seconds, with leading zeros<\/td>\n<td>00-59<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>T<\/code><\/td>\n<td>Timezone abbreviation<\/td>\n<td>Eg., EST, MDT \u2026<\/td>\n<\/tr>\n<tr>\n<th colspan=\"3\" style=\"background:#eee;padding: 5px 10px\">Full Date\/Time<\/th>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>c<\/code><\/td>\n<td>ISO 8601<\/td>\n<td>2004-02-12T15:19:21+00:00<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>r<\/code><\/td>\n<td><a title=\"RFC 2822\" href=\"http:\/\/tools.ietf.org\/html\/rfc2822\">RFC 2822<\/a><\/td>\n<td>Thu, 21 Dec 2000 16:01:07 +0200<\/td>\n<\/tr>\n<tr>\n<td style=\"width:10%;text-align:center\"><code>U<\/code><\/td>\n<td>Unix timestamp (seconds since Unix Epoch)<\/td>\n<td>1455880176<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n<h2 class=\"wp-block-heading\">Format String Examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some examples of date format with the result output.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>F j, Y g:i a<\/code> &#8211; November 6, 2010 12:50 am<\/li>\n\n\n\n<li><code>F j, Y<\/code> &#8211; November 6, 2010<\/li>\n\n\n\n<li><code>F, Y<\/code> &#8211; November, 2010<\/li>\n\n\n\n<li><code>g:i a<\/code> &#8211; 12:50 am<\/li>\n\n\n\n<li><code>g:i:s a<\/code> &#8211; 12:50:48 am<\/li>\n\n\n\n<li><code>l, F jS, Y<\/code> &#8211; Saturday, November 6th, 2010<\/li>\n\n\n\n<li><code>M j, Y @ G:i<\/code> &#8211; Nov 6, 2010 @ 0:50<\/li>\n\n\n\n<li><code>Y\/m\/d \\a\\t g:i A<\/code> &#8211; 2010\/11\/06 at 12:50 AM<\/li>\n\n\n\n<li><code>Y\/m\/d \\a\\t g:ia<\/code> &#8211; 2010\/11\/06 at 12:50am<\/li>\n\n\n\n<li><code>Y\/m\/d g:i:s A<\/code> &#8211; 2010\/11\/06 12:50:48 AM<\/li>\n\n\n\n<li><code>Y\/m\/d<\/code> &#8211; 2010\/11\/06<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Overriding General Settings Formatting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Functions for Time and Date accept <strong>format string<\/strong> as a parameter in order to override default Date and Time formatting for certain places in theme or plugin files. Just the same as in <a href=\"\/support\/article\/settings-general-screen\/\">General Settings<\/a>, this format string is a template of characters where each character represents specific part of Date or Time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the template file, setting the Date and Time format string as a parameter for <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/the_time\/\"><code>the_time()<\/code><\/a> template tag, would look something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">Posted on &lt;?php the_time( 'l, F jS, Y' ); ?&gt;.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Which will render on the frontend of your site as following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Posted on Friday, September 24th, 2004.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Localization<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To localize Date and Time, use the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_date\/\">wp_date()<\/a> function. The <code>wp_date()<\/code> function basically behaves like the PHP <a href=\"http:\/\/php.net\/manual\/en\/function.date.php\">date()<\/a> function, except that it also translates things like month names and weekdays and similar into the current locale for the site. You can replace a call to <code>date()<\/code> with a call to <code>wp_date()<\/code>, using the same arguments.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$date = wp_date( 'F j, Y' );\n$time = wp_date( 'g:i a' );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, you can wrap your predefined format in <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/__\/\">__()<\/a> or <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/_e\/\">_e()<\/a> in order to allow translators to adjust the Date and Time to the proper local format. If you do so, then you should also include a translator comment, to let the translators know what the date format is referring to and where it is used, so they can convert it accurately.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">__( 'Y\/m\/d g:i:s a', 'textdomain' );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Escaping<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some letters do not have an associated format in the PHP date function. For example <code>x<\/code> passed in the format string will currently return a literal <code>x<\/code>. However, this can change at some point in the future and <code>x<\/code> may have a format associated with it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is why you should always escape literal character in a date formatted string with <code>\\<\/code>. Note that, in following example, every letter of word <code>of<\/code> is escaped.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">wp_date( __( 'l jS \\o\\f F Y', 'textdomain' ) );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This example will render as following on the frontend of your site:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Saturday 25th of February 2017<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Customizing the Time and Date Format Certain WordPress tag functions are used to display or return date and time information; the_date() and the_time() are examples of this. By default, these functions will display or return date and time in format as it is set in Administration &gt; Settings &gt; General. This is the place where [&hellip;]<\/p>\n","protected":false},"author":7311168,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false},"category":[86,78],"class_list":["post-10851332","helphub_article","type-helphub_article","status-publish","hentry","category-publishing","category-support-guides"],"revision_note":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10851332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles"}],"about":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/types\/helphub_article"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/comments?post=10851332"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10851332\/revisions"}],"predecessor-version":[{"id":16365911,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10851332\/revisions\/16365911"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wporg\/v1\/users\/yuli-yang"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/media?parent=10851332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/category?post=10851332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}