java Thymeleaf:使用#dates.format() 函数来格式化日期并进行国际化。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28808838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:13:03  来源:igfitidea点击:

Thymeleaf: Use #dates.format() function for format date with internatinalization.

javaspring-mvcthymeleaf

提问by Harmeet Singh Taara

I am using Thymeleaf #dates.format()function for format date in view layer. I create one internatinalization properties file for pic the date format. i am using #dates.format(date, (#{app.dateformat}))function like this. but Thymeleafthrow an parse exception. Because thymeleaf now resolve the app.dateformat. How i use date format internationalization way in thymeleaf. Following is an exception:

我正在使用Thymeleaf #dates.format()视图层中的格式日期函数。我为 pic 日期格式创建了一个国际化属性文件。我正在使用这样的#dates.format(date, (#{app.dateformat}))功能。但Thymeleaf抛出解析异常。因为 thymeleaf 现在解决了app.dateformat. 我如何在 thymeleaf 中使用日期格式国际化方式。以下是一个例外:

org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'

回答by lgd

You should use this syntax instead :

您应该改用此语法:

${#dates.format(date, #messages.msg('app.dateformat'))}

#messages: utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.

#messages: 用于获取变量表达式内外部化消息的实用方法,与使用 #{...} 语法获取它们的方式相同。

Source

来源