【问题标题】:getDateTimeInstance(): Different Behavior for Different LanguagesgetDateTimeInstance():不同语言的不同行为
【发布时间】:2022-11-16 23:38:47
【问题描述】:

我正在使用此函数 sap.ui.core.format.DateFormat.getDateTimeInstance({ pattern: "yyyy-MM-dd HH:mm" });

日期格式在“DE”中工作正常,但在“EN”中返回错误值。 两种语言的时间都是 24 小时,我需要的是英语应该显示上午和下午。

if (oData) {
   let oDateFormat = DateFormat.getDateTimeInstance({ pattern: "yyyy-MM-dd HH:mm"});
   oData.forEach(item => {
                 item.startDataTime = oDateFormat.format(new Date(item.startDataTime));                    
})

【问题讨论】:

  • 目标UI5版本是多少?
  • 您是否尝试过直接在 XML 中通过属性绑定、type 和 formatOptions 让框架在没有自定义 JS 代码的情况下进行格式化?
  • @BoghyonHoffmann '1.108.0'

标签: javascript sapui5


【解决方案1】:

根据 http://unicode.org/reports/tr35/tr35-dates.html#table-date-field-symbol-table,HH 匹配“24 小时周期格式”,而 hh 匹配“12 小时周期格式”。

尝试将 HH 替换为 hh 并附加 aa 以显示 AM/PM。

// DateFormat required from "sap/ui/core/format/DateFormat"
DateFormat.getDateTimeInstance({ pattern: "yyyy-MM-dd hh:mm aa"});

例如,使用上述实例和模式进行格式化会返回 "2022-11-16 04:41 PM"。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2017-12-21
    相关资源
    最近更新 更多