Add o'clock/Uhr to a globalize.js formatted date

415 views Asked by At

Pretty simple question: I want to add a switch to my globalize format skeleton, so that it adds an "o'clock" or German "Uhr" after the time. Right now, I'm using the following pattern:

yMMddHHmm

I found the o'clock string in the respective cldr files, but I don't know how to add them to the skeleton.

Here's my code:

Globalize.formatDate(dTermin, { skeleton: 'yMMddHHmm' });

Thank you in advance for your help!

1

There are 1 answers

4
Rafael Xavier On

There's no skeleton that would give you "o'clock" kinda output [1]. Although, if you really want that format and are willing to provide the i18n data for all the locales you think could support it you can use globalize's raw option like:

// Not recommended anyway...
if (locale === "en") {
    formatter = globalize.dateFormatter({raw: "HH 'o''clock'"});
}

Though, it's usually a not recommended approach since you have to maintain this list of custom formatters yourself.

1: In order to check, I've grep'ed the whole CLDR and found no match.