如何输出没有时间的Edm.DateTime?
问题描述:
<m:Text text="{
path: 'Begda',
type: 'sap.ui.model.type.DateTime',
formatOptions: {
style: 'short'
},
constraints: {
nullable: true,
displayFormat: 'Date'
}
}"/>
从文档中我明白我应该使用displayFormat: 'Date'
来显示日期。预期的输出是日/月/年(或另一个本地化的顺序)的本地化显示。如何输出没有时间的Edm.DateTime?
我得到的输出是17/08/16 02:00
。
答
你是非常接近的。为了显示日期仅..:
- 同this question,您需要使用OData的类型,以取代常规型:
- >sap.ui.model.type.DateTime
sap.ui.model.odata.type.DateTime
。该类表示OData V2原语类型Edm.DateTime。
-
然后使用这些约束,如前所述here:
constraints: { isDateOnly: true, displayFormat: 'Date' }
关于
isDateOnly
:如果为true,仅使用日期部分,时间部分始终是00: 00:00和时区是UTC以避免与时区相关的问题
没有必要使用pattern
摆弄。
答
指定模式属性,并更改类型属性sap.ui.model.type.Date:
<Text text="{path: '/someDate',
type: 'sap.ui.model.type.Date',
formatOptions: {
source: {
pattern: 'yyyy-MM-ddTHH:mm:ss.AAAZ' <-- Source property is optional
},
pattern: 'yyyy/MM/dd'
}
}" />