SAPUI5:输出格式化日期 [英] SAPUI5: Output formatted date
问题描述
我已经开发了带有XML视图的SAPUI5应用程序.
I´ve developed an SAPUI5 application with an XML-View.
现在我要正确格式化日期.
Now I want to format a date correctly.
我通过以下方式尝试过:
I tried it the following way:
<Text text="{
path: 'model>LastCommDate',
type: 'sap.ui.model.type.Date',
formatOptions: {
pattern: 'yyyy/MM/dd'
}
}" />
错误消息:
datajs.js:17 Uncaught TypeError: j.getTime is not a function
在没有formatOptions
和type
的情况下,我得到的是未格式化的输出.
Without the formatOptions
and type
I get the unformatted output.
<Text text="{
path: 'model>LastCommDate'
}" />
输出:2015-06-16T00:00:00
与Time
相同的问题:
时间对象的模式应该如何看待?
Same question for Time
:
How should look the patterns for a time-object?
类型:sap.ui.model.type.Time
未格式化的输出:PT19H21M29S
推荐答案
首先,它取决于您的日期在模型中的存储方式. 如果您将其作为JavaScript日期对象,则您的示例应该可以使用.
First of all it depends on how your date is stored in the model. If you have it as JavaScript date object, your example should work.
如果您将其作为字符串,则需要告诉Date类型如何解析该字符串,即期望使用哪种格式.为此,您可以在formatOptions
中添加一个source
部分:
If you have it as a string, you need to tell the Date type how to parse the string, i.e. which format to expect. You do so by adding a source
section to the formatOptions
:
<Text text="{
path: 'model>LastCommDate',
type: 'sap.ui.model.type.Date',
formatOptions: {
source: {
pattern: 'yyyy-MM-ddTHH:mm:ss'
},
pattern: 'yyyy/MM/dd'
}
}" />
有关两者的比较,请参见此示例.
For a comparison of the two see this example.
这篇关于SAPUI5:输出格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!