转换日期Freemarker [英] Converting Dates Freemarker

查看:213
本文介绍了转换日期Freemarker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使以下各项起作用,但我无法显示正确的值。

I'm trying to get the following to work but I can't get the correct value to display.

假设将SHIPPING_DATE视为值= 2016/05/23的字符串:

Assuming SHIPPING_DATE is treated as a string with the value = 2016/05/23:

<#setting date_format="MM/dd/yyyy">
<#setting locale="en_US">

<#assign ship_date>${SHIPPING_DATE}</#assign>

${ship_date?date("MM/dd/yyyy")}

输出为 12/05/0190 ,但是我希望 2016年5月23日

The output is 12/05/0190 but I'm expecting 05/23/2016. Will someone help but also explain what I'm doing wrong, please?

推荐答案

如果您有 string

If you have a string in ship_date like 2016/05/23, then you can parse it to a real date value with ship_date?date("yyyy/MM/dd"). Note that it's not MM/dd/yyyy, as in your example. ?date means "convert to date", and you specify to it how to interpret the string. Then, when you print a real date value (not a string) with ${...}, then it will be converted to string according the data_format configuration setting, so then MM/dd/yyyy will be good. It doesn't mater how that real date value was get (like with string?date(format) or directly from the data-model).

这篇关于转换日期Freemarker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆