I am doing date format using this function
// DateFormat required from "sap/ui/core/format/DateFormat"
DateFormat.getDateTimeInstance({ pattern: "yyyy-MM-dd HH:mm" });
The format is working fine in "DE" but it is returning wrong value in "EN". In both languages, the time is 24 hour. What I need is:
- In English, the time text should contain AM or PM.
- In German, the time text should be in the 24h format.
How can this be achieved?
Target UI5 version: 1.108
According to the Unicode's Date Field Symbol table:
HHcorresponds to the "24-hour-cycle format"hhcorresponds to the "12-hour-cycle format"jj"is the only way to [...] request a locale's preferred time cycle type (12-hour or 24-hour)."If not required otherwise, I'd strongly discourage from hardcoding the
patternin the format options in order to let the framework format the date and time depending on the user locale. You can use theformatoption instead to specify which symbol to incorporate (e.g.jjinstead ofhhorHH) when formatting the date time value.Run this snippet to see the result:
Given today at 23:00:00Z:
API reference:
sap/ui/core/format/DateFormat.getDateTimeInstanceSame can be achieved in property binding within XML declaratively via
typeandformatOptions.API reference:
sap/ui/model/odata/type/DateTimeOffsetDocumentation (must-read): Dates, Times, Timestamps, and Time Zones
Documentation: Formatting, Parsing, and Validating Data — Data Binding (in XML)