| <!doctype html> |
| <!-- Generated by FreeMarker/Docgen from DocBook --> |
| <html lang="en" class="page-type-section"> |
| <head prefix="og: http://ogp.me/ns#"> |
| <meta charset="utf-8"> |
| <title>Built-ins for date/time/date-time values - Apache FreeMarker Manual</title> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| <meta name="format-detection" content="telephone=no"> |
| <meta property="og:site_name" content="Apache FreeMarker Manual"> |
| <meta property="og:title" content="Built-ins for date/time/date-time values"> |
| <meta property="og:locale" content="en_US"> |
| <meta property="og:url" content="https://freemarker.apache.org/docs/ref_builtins_date.html"> |
| <link rel="canonical" href="https://freemarker.apache.org/docs/ref_builtins_date.html"> |
| <link rel="icon" href="favicon.png" type="image/png"> |
| <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono"> |
| <link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1707770044859"> |
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/cookie-bar/cookiebar-latest.min.js"></script> |
| </head> |
| <body itemscope itemtype="https://schema.org/Code"> |
| <meta itemprop="url" content="https://freemarker.apache.org/docs/"> |
| <meta itemprop="name" content="Apache FreeMarker Manual"> |
| |
| <!--[if lte IE 9]> |
| <div class="oldBrowserWarning" style="display: block"> |
| Unsupported web browser - Use a modern browser to view this website! |
| </div> |
| <![endif]--> <div class="oldBrowserWarning"> |
| Unsupported web browser - Use a modern browser to view this website! |
| </div> |
| <div class="header-top-bg"><div class="site-width header-top"><div id="hamburger-menu" role="button"></div> <div class="logo"> |
| <a href="https://freemarker.apache.org" role="banner"><img itemprop="image" src="logo.png" alt="FreeMarker"></a> </div> |
| <ul class="tabs"><li><a href="https://freemarker.apache.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="https://freemarker.apache.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/projects/FREEMARKER" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="https://freemarker.apache.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="search-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"> <div class="breadcrumbs"> |
| <ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref.html"><span itemprop="name">Template Language Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins.html"><span itemprop="name">Built-in Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins_date.html"><span itemprop="name">Built-ins for date/time/date-time values</span></a></li></ul> </div> |
| <div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width"> |
| <div class="content-wrapper"> |
| <div id="table-of-contents-wrapper" class="col-left"> |
| <script>var breadcrumb = ["Apache FreeMarker Manual","Template Language Reference","Built-in Reference","Built-ins for date/time/date-time values"];</script> |
| <script src="toc.js?1707770044859"></script> |
| <script src="docgen-resources/main.min.js?1707770044859"></script> |
| </div> |
| <div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="ref_builtins_number.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_boolean.html"><span>Next</span></a></div><div class="title-wrapper"> |
| <h1 class="content-header header-section1" id="ref_builtins_date" itemprop="headline">Built-ins for date/time/date-time values</h1> |
| </div></div><div class="page-menu"> |
| <div class="page-menu-title">Page Contents</div> |
| <ul><li><a class="page-menu-link" href="#ref_builtin_date_datetype" data-menu-target="ref_builtin_date_datetype">date, time, datetime (when used with a date/time/date-time |
| value)</a></li><li><a class="page-menu-link" href="#ref_builtin_date_if_unknown" data-menu-target="ref_builtin_date_if_unknown">date_if_unknown, time_if_unknown, datetime_if_unknown</a></li><li><a class="page-menu-link" href="#ref_builtin_date_iso" data-menu-target="ref_builtin_date_iso">iso_...</a></li><li><a class="page-menu-link" href="#ref_builtin_string_for_date" data-menu-target="ref_builtin_string_for_date">string (when used with a date/time/date-time value)</a></li></ul> </div> |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="ref_builtin_date_datetype">date, time, datetime (when used with a date/time/date-time |
| value)</h2> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <p>These built-ins can be used to specify which parts of the |
| date-like variable are in use:</p> |
| |
| <ul> |
| <li> |
| <p><code class="inline-code">date</code>: Date only, no time of the |
| day.</p> |
| </li> |
| |
| <li> |
| <p><code class="inline-code">time</code>: Only the time of the day, no date |
| part</p> |
| </li> |
| |
| <li> |
| <p><code class="inline-code">datetime</code>: Both date and time</p> |
| </li> |
| </ul> |
| |
| <p>Ideally, you do not need to use these built-ins. |
| Unfortunately, because of the technical limitations of the Java |
| platform, FreeMarker sometimes can't find out which parts of a |
| date-like value is a date, a time or a date-time; ask the |
| programmers which variables has this problem. If FreeMarker has to |
| execute an operation where this information is needed -- such as |
| displaying the value as text -- but it does not know which parts are |
| in use, it will stop with error. This is when you have to use these |
| built-ins. For example, assume <code class="inline-code">openingTime</code> is a |
| such problematic variable:</p> |
| |
| |
| |
| <div class="code-block role-template"> |
| <div class="code-block-label">Template</div><pre class="code-block-body"><#assign x = openingTime> <#-- no problem can occur here --> |
| ${openingTime?time} <#-- without ?time it would fail --> |
| <#-- For the sake of better understanding, consider this: --> |
| <#assign openingTime = openingTime?time> |
| ${openingTime} <#-- this will work now --></pre> </div> |
| |
| |
| <p>These built-ins can also be used to convert date-time values |
| to date or time. For example:</p> |
| |
| |
| |
| <div class="code-block role-template"> |
| <div class="code-block-label">Template</div><pre class="code-block-body">Last updated: ${lastUpdated} <#-- assume that lastUpdated is a date-time value --> |
| Last updated date: ${lastUpdated?date} |
| Last updated time: ${lastUpdated?time}</pre> </div> |
| |
| |
| <p>will output something like:</p> |
| |
| |
| |
| <div class="code-block role-output"> |
| <div class="code-block-label">Output</div><pre class="code-block-body">Last updated: 04/25/2003 08:00:54 PM |
| Last updated date: 04/25/2003 |
| Last updated time: 08:00:54 PM</pre> </div> |
| |
| |
| <p>If the left side of the <code class="inline-code">?</code> is string, then |
| these built-ins <a href="ref_builtins_string.html#ref_builtin_string_date">convert |
| strings to date/time/date-time</a>.</p> |
| |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="ref_builtin_date_if_unknown">date_if_unknown, time_if_unknown, datetime_if_unknown</h2> |
| |
| |
| <div class="callout note"> |
| <strong class="callout-label">Note:</strong> |
| |
| <p>This built-in exists since FreeMarker 2.3.21.</p> |
| </div> |
| |
| |
| <p>The <code class="inline-code">date_if_unknown</code>, |
| <code class="inline-code">time_if_unknown</code>, |
| <code class="inline-code">datetime_if_unknown</code> built-ins mark a date-like |
| value with some of the sub-types: date without time, time, or |
| date-time, respectively. However, if the value already holds this |
| information, the built-in has no effect. That is, it will never |
| convert the sub-type of a value, it only adds the sub-type if it was |
| unknown.</p> |
| |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="ref_builtin_date_iso">iso_...</h2> |
| |
| |
| |
| |
| |
| |
| <div class="callout note"> |
| <strong class="callout-label">Note:</strong> |
| |
| <p><em>These built-ins are deprecated</em> since |
| FreeMarker 2.3.21, where the <code class="inline-code">date_format</code>, |
| <code class="inline-code">time_format</code> and |
| <code class="inline-code">datetime_format</code> settings understand |
| <code class="inline-code">"iso"</code> (for ISO 8601:2004 format) and |
| <code class="inline-code">"xs"</code> (for XML Schema format) in additionally to |
| the Java <code class="inline-code">SimpleDateFormat</code> patterns. Thus the |
| default format can be set to ISO 8601, or for one time ISO |
| formatting you can use <code class="inline-code">myDate?string.iso</code>. <a href="ref_directive_setting.html#topic.dateTimeFormatSettings">See more |
| here...</a></p> |
| </div> |
| |
| |
| <p>These built-ins convert a date, time or date-time value to |
| string that follows ISO 8601:2004 "extended" format.</p> |
| |
| <p>This built-in has several variations: |
| <code class="inline-code">iso_utc</code>, <code class="inline-code">iso_local</code>, |
| <code class="inline-code">iso_utc_nz</code>, <code class="inline-code">iso_local_nz</code>, |
| <code class="inline-code">iso_utc_m</code>, <code class="inline-code">iso_utc_m_nz</code>, etc. |
| The name is constructed from the following words in this order, each |
| separated with a <code class="inline-code">_</code> from the next:</p> |
| |
| <div class="orderedlist"><ol type="1"> |
| <li> |
| <p><code class="inline-code">iso</code> (required)</p> |
| </li> |
| |
| <li> |
| <p>Either <code class="inline-code">utc</code> or <code class="inline-code">local</code> |
| (required (except when it's given with a parameter, but see that |
| later)): Specifies whether you want to print the |
| date/time/date-time according to UTC or according the current |
| time zone. The current time zone is decided by the |
| <code class="inline-code">time_zone</code> FreeMarker setting and is normally |
| configured by the programmers outside the templates (but it can |
| also be set in a template, like <code class="inline-code"><#setting |
| time_zone="America/New_York"></code> for example). Note |
| that if the <code class="inline-code">sql_date_and_time_time_zone</code> |
| FreeMarker setting is set and non-<code class="inline-code">null</code>, then |
| for <code class="inline-code">java.sql.Date</code> and |
| <code class="inline-code">java.sql.Time</code> values (i.e., for date-only and |
| time-only values that are coming from database via SQL) |
| <code class="inline-code">local</code> will mean that time zone instead of the |
| value of the <code class="inline-code">time_zone</code> setting.</p> |
| </li> |
| |
| <li> |
| <p>Either <code class="inline-code">h</code> or <code class="inline-code">m</code> or |
| <code class="inline-code">ms</code> (optional): The accuracy of the time part. |
| When omitted, it defaults to seconds accuracy (like |
| <code class="inline-code">12:30:18</code>). <code class="inline-code">h</code> means hours |
| accuracy (like <code class="inline-code">12</code>), <code class="inline-code">m</code> |
| means minutes accuracy (<code class="inline-code">12:30</code>), and |
| <code class="inline-code">ms</code> means milliseconds accuracy |
| (<code class="inline-code">12:30:18.25</code>, where we have 250 ms). Note |
| that when using <code class="inline-code">ms</code>, the milliseconds are |
| displayed as fraction seconds (following the standard) and will |
| not have trailing <code class="inline-code">0</code>-s. Thus, if the the |
| millisecond part happens to be <code class="inline-code">0</code>, the whole |
| fraction second part will be omitted. Also note that the |
| fraction seconds are always separated with a dot , not with |
| comma (to follow the Web conventions and XML Schema |
| time/dateTime canonical format).</p> |
| </li> |
| |
| <li> |
| <p><code class="inline-code">nz</code> (optional): <code class="inline-code">nz</code> |
| (like in <code class="inline-code">${foo?utc_local_nz}</code>) stands for |
| "no zone", which means that the time zone offset |
| (like <code class="inline-code">+02:00</code> or or <code class="inline-code">-04:30</code> |
| or <code class="inline-code">Z</code>) will not be displayed. If this part is |
| omitted (like in <code class="inline-code">${foo?utc_local}</code>) the zone |
| will be displayed, except in two cases:</p> |
| |
| <ul> |
| <li> |
| <p>If the value is a date (no time part) value (again, |
| ISO 8901 doesn't allow it then)</p> |
| </li> |
| |
| <li> |
| <p>If the value is a <code class="inline-code">java.sql.Time</code> and |
| the <code class="inline-code">incompatible_improvements</code> (often set |
| via the Java <code class="inline-code">Configuration</code> constructor |
| parameter) FreeMarker configuration setting is at least |
| 2.3.21 (or 2.3.24 when you are inside a string literal). |
| This is because most databases store time values that aren't |
| in any time zone, but just store hour, minute, second, and |
| decimal second field values, so showing the time zone |
| doesn't make sense.</p> |
| </li> |
| </ul> |
| |
| <p>Note that since FreeMarker 2.3.19, the offset always |
| contains the minutes for XML Schema date/time/dateTime format |
| compliance. (However, if you primarily generate for the XML |
| Schema format, use the xs format.)</p> |
| </li> |
| </ol></div> |
| |
| <p>Example:</p> |
| |
| |
| |
| <div class="code-block role-template"> |
| <div class="code-block-label">Template</div><pre class="code-block-body"><#assign aDateTime = .now> |
| <#assign aDate = aDateTime?date> |
| <#assign aTime = aDateTime?time> |
| |
| Basic formats: |
| ${aDate?iso_utc} |
| ${aTime?iso_utc} |
| ${aDateTime?iso_utc} |
| |
| Different accuracies: |
| ${aTime?iso_utc_ms} |
| ${aDateTime?iso_utc_m} |
| |
| Local time zone: |
| ${aDateTime?iso_local}</pre> </div> |
| |
| |
| <p>A possible output (depends on current time and time |
| zone):</p> |
| |
| |
| |
| <div class="code-block role-output"> |
| <div class="code-block-label">Output</div><pre class="code-block-body">Basic formats: |
| 2011-05-16 |
| 21:32:13Z |
| 2011-05-16T21:32:13Z |
| |
| Different accuracies: |
| 21:32:13.868Z |
| 2011-05-16T21:32Z |
| |
| Local time zone: |
| 2011-05-16T23:32:13+02:00</pre> </div> |
| |
| |
| <p>There is yet another group of <code class="inline-code">iso_...</code> |
| built-in variants, where you omit the <code class="inline-code">local</code> or |
| <code class="inline-code">utc</code> word from the name and instead specify the |
| time zone as a parameter to the built-in. Example:</p> |
| |
| |
| |
| <div class="code-block role-template"> |
| <div class="code-block-label">Template</div><pre class="code-block-body"><#assign aDateTime = .now> |
| ${aDateTime?iso("UTC")} |
| ${aDateTime?iso("GMT-02:30")} |
| ${aDateTime?iso("Europe/Rome")} |
| |
| The usual variations are supported: |
| ${aDateTime?iso_m("GMT+02")} |
| ${aDateTime?iso_m_nz("GMT+02")} |
| ${aDateTime?iso_nz("GMT+02")}</pre> </div> |
| |
| |
| <p>A possible output (depends on current time and time |
| zone):</p> |
| |
| |
| |
| <div class="code-block role-output"> |
| <div class="code-block-label">Output</div><pre class="code-block-body">2011-05-16T21:43:58Z |
| 2011-05-16T19:13:58-02:30 |
| 2011-05-16T23:43:58+02:00 |
| |
| The usual variations are supported: |
| 2011-05-16T23:43+02:00 |
| 2011-05-16T23:43 |
| 2011-05-16T23:43:58</pre> </div> |
| |
| |
| <p>If the time zone parameter can't be interpreted, the template |
| processing will be terminated with error.</p> |
| |
| <p class="programmers-note">The parameter can be a |
| <code class="inline-code">java.util.TimeZone</code> object too (which is possibly |
| the return value of a Java method, or it's in the data-model), not |
| just a string.</p> |
| |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="ref_builtin_string_for_date">string (when used with a date/time/date-time value)</h2> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <p>This built-in converts a date to a string, with the specified |
| formatting.</p> |
| |
| <div class="callout note"> |
| <strong class="callout-label">Note:</strong> |
| |
| <p>You should need this built-in rarely, as the default format |
| of date/time/date-time values can be specified globally <a href="ref_directive_setting.html#topic.dateTimeFormatSettings">with the |
| <code>date_format</code>, <code>time_format</code> and |
| <code>datetime_format</code> settings</a> of FreeMarker. |
| Use this built-in only at the places where the desired format |
| differs from the one normally used. For the other places the |
| default format should be set properly by the programmers, outside |
| the templates.</p> |
| </div> |
| |
| |
| <p>The desired format can be specified like |
| <code class="inline-code">?string.<em class="code-color">format</em></code> or |
| <code class="inline-code">?string["<em class="code-color">format</em>"]</code>(or |
| the historical equivalent, |
| <code class="inline-code">?string("<em class="code-color">format</em>")</code>). |
| These are equivalent, except that with the quoted formats you can |
| include any characters in the |
| <code class="inline-code"><em class="code-color">format</em></code>, like spaces. |
| The syntax of <code class="inline-code"><em class="code-color">format</em></code> |
| is exactly the same as of the <code class="inline-code">date_format</code>, |
| <code class="inline-code">time_format</code> and |
| <code class="inline-code">datetime_format</code> configuration settings; <a href="ref_directive_setting.html#topic.dateTimeFormatSettings">see the documentation of the |
| possible values there</a>.</p> |
| |
| <p>Example: If the locale of the output is U.S. English, and the |
| time zone is the U.S. Pacific Time zone, and |
| <code class="inline-code">openingTime</code> is a |
| <code class="inline-code">java.sql.Time</code>, <code class="inline-code">nextDiscountDay</code> |
| is <code class="inline-code">java.sql.Date</code> and |
| <code class="inline-code">lastUpdated</code> is |
| <code class="inline-code">java.sql.Timestamp</code> or |
| <code class="inline-code">java.util.Date</code> then this:</p> |
| |
| |
| |
| <div class="code-block role-template"> |
| <div class="code-block-label">Template</div><pre class="code-block-body"><#-- Predefined format names: --> |
| |
| ${openingTime?string.short} |
| ${openingTime?string.medium} |
| ${openingTime?string.long} |
| ${openingTime?string.full} |
| ${openingTime?string.xs} <#-- XSD xs:time --> |
| ${openingTime?string.iso} <#-- ISO 8601 time --> |
| |
| ${nextDiscountDay?string.short} |
| ${nextDiscountDay?string.medium} |
| ${nextDiscountDay?string.long} |
| ${nextDiscountDay?string.full} |
| ${nextDiscountDay?string.xs} <#-- XSD xs:date --> |
| ${nextDiscountDay?string.iso} <#-- ISO 8601 date --> |
| |
| ${lastUpdated?string.short} |
| ${lastUpdated?string.medium} |
| ${lastUpdated?string.long} |
| ${lastUpdated?string.full} |
| ${lastUpdated?string.medium_short} <#-- medium date, short time --> |
| ${lastUpdated?string.xs} <#-- XSD xs:dateTime --> |
| ${lastUpdated?string.iso} <#-- ISO 8601 combined date and time --> |
| |
| <#-- <a href="pgui_config_custom_formats.html">Programmer-defined named format</a> (@ + name): --> |
| ${lastUpdated?string.@fileDate} |
| |
| <#-- Advanced ISO 8601 and XSD formatting: --> |
| ${lastUpdated?string.iso_m_u} |
| ${lastUpdated?string.xs_ms_nz} |
| |
| <#-- SimpleDateFormat patterns: --> |
| ${lastUpdated?string["dd.MM.yyyy, HH:mm"]} |
| ${lastUpdated?string["EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'"]} |
| ${lastUpdated?string["EEE, MMM d, ''yy"]} |
| ${lastUpdated?string.yyyy} <#-- Same as ${lastUpdated?string["yyyy"]} --></pre> </div> |
| |
| |
| <p>will print something like this:</p> |
| |
| |
| |
| <div class="code-block role-output"> |
| <div class="code-block-label">Output</div><pre class="code-block-body">01:45 PM |
| 01:45:09 PM |
| 01:45:09 PM PST |
| 01:45:09 PM PST |
| 13:45:09-08:00 |
| 13:45:09-08:00 |
| |
| 2/20/07 |
| Apr 20, 2007 |
| April 20, 2007 |
| Friday, April 20, 2007 |
| 2007-02-20-08:00 |
| 2007-02-20 |
| |
| 2/20/07 01:45 PM |
| Feb 20, 2007 01:45:09 PM |
| February 20, 2007 01:45:09 PM PST |
| Friday, February 20, 2007 01:45:09 PM PST |
| Feb 8, 2003 9:24 PM |
| 2007-02-20T13:45:09-08:00 |
| 2007-02-20T13:45:09-08:00 |
| |
| Apr/20/2007 13:45 |
| |
| 2007-02-20T21:45Z |
| 2007-02-20T13:45:09.000 |
| |
| 08.04.2003 21:24 |
| Tuesday, April 08, 2003, 09:24 PM (PDT) |
| Tue, Apr 8, '03 |
| 2003</pre> </div> |
| |
| |
| <p>Note that with custom formats like in |
| <code class="inline-code">lastUpdated?string.@fileDate</code> above, templates can |
| just refer to the application-domain meaning, and the exact format |
| can be specified outside the templates, on a central place. |
| (Programmers can read about <a href="pgui_config_custom_formats.html">defining such named formats |
| here...</a>)</p> |
| |
| <div class="callout warning"> |
| <strong class="callout-label">Warning!</strong> |
| |
| <p>Unfortunately, because of the limitations of the Java |
| platform, it can happen that you have date-like variables in the |
| data-model, where FreeMarker can't decide if the variable is a |
| date (year, month, day), or a time (hour, minute, second, |
| millisecond) or a date-time. In this case, FreeMarker doesn't know |
| how to display the value when you write something like |
| <code class="inline-code">${lastUpdated?string.short}</code> or |
| <code class="inline-code">${lastUpdated?string.xs}</code>, i.e., a format that |
| doesn't specify the exact fields to display, or if you simply use |
| <code class="inline-code">${lastUpdated}</code>. Then it will have to stop with |
| error. To prevent this, you can help FreeMarker with the <a href="#ref_builtin_date_datetype"><code>?date</code>, |
| <code>?time</code> and <code>?datetime</code> |
| built-ins</a>. For example: |
| <code class="inline-code">${lastUpdated?datetime?string.short}</code>. Ask the |
| programmers if certain variables of the data-model have this |
| problem, or always use <code class="inline-code">?date</code>, |
| <code class="inline-code">?time</code> and <code class="inline-code">?datetime</code> |
| built-ins to be on the safe side.</p> |
| </div> |
| |
| |
| <div class="callout note"> |
| <strong class="callout-label">Note:</strong> |
| |
| <p>You never need to use <code class="inline-code">?date</code>, |
| <code class="inline-code">?time</code> or <code class="inline-code">?datetime</code> with |
| format patterns like <code class="inline-code">"yyyy.MM.dd HH:mm"</code>, since |
| with the pattern you tell FreeMarker what parts of the date to |
| show. However, FreeMarker will trust you blindly, so you can show |
| "noise" if you display parts that are actually not stored in the |
| variable. For example, <code class="inline-code">${openingTime?string["yyyy-MM-dd |
| hh:mm:ss a"]}</code>, where <code class="inline-code">openingTime</code> |
| stores only time, will display <code class="inline-code">1970-01-01 09:24:44 |
| PM</code>.</p> |
| </div> |
| |
| |
| <p>To prevent misunderstandings, the format need not be a string |
| literal, it can be a variable or any other expression as far as it |
| evaluates to a string. For example, it can be like |
| <code class="inline-code">"<em class="code-color">...</em>"?string[myFormat]</code>.</p> |
| |
| <p>See also: <a href="dgui_template_valueinsertion.html#dgui_template_valueinserion_universal_date">the |
| interpolation of dates</a></p> |
| <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_builtins_number.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_boolean.html"><span>Next</span></a></div></div></div></div> </div> |
| </div> |
| <div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="https://freemarker.apache.org/">What is FreeMarker?</a></li><li><a href="https://freemarker.apache.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="app_faq.html">FAQ</a></li><li><a itemprop="license" href="app_license.html">License</a></li><li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy policy</a></li></ul></div><div class="column"><h3 class="column-header">Often used / Reference</h3><ul><li><a href="https://try.freemarker.apache.org/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li><li><a href="api/freemarker/core/Configurable.html#setSetting-java.lang.String-java.lang.String-">Configuration settings</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href="https://github.com/apache/freemarker">Github project page</a></li><li><a href="https://issues.apache.org/jira/projects/FREEMARKER">Report a bug</a></li><li><a href="https://freemarker.apache.org/report-security-vulnerabilities.html">Report security vulnerability</a></li><li><a href="https://stackoverflow.com/questions/ask?tags=freemarker">Get help on StackOverflow</a></li><li><a href="https://twitter.com/freemarker">Announcements on Twitter</a></li><li><a href="https://freemarker.apache.org/mailing-lists.html">Discuss on mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/apache/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="https://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated"> |
| Last generated: |
| <time itemprop="dateModified" datetime="2024-02-12T20:34:04Z" title="Monday, February 12, 2024 at 8:34:04 PM Greenwich Mean Time">2024-02-12 20:34:04 GMT</time>, for Freemarker 2.3.32 </p> |
| <p class="copyright"> |
| © <span itemprop="copyrightYear">1999</span>–2024 |
| <a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="https://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners. </p> |
| </div></div></div></body> |
| </html> |