0

Is there a way to change month title Jänner to Janner while using below code?

var date = new Date(Date.UTC(2020, 0, 20, 3, 23, 16, 738));
console.log(new Intl.DateTimeFormat('de-at', { month: 'long' }).format(date));
date = new Date(Date.UTC(2020, 2, 20, 3, 23, 16, 738));
console.log(new Intl.DateTimeFormat('de-at', { month: 'long' }).format(date));

Output:

'Jänner'
'März'

Expected output:

'Janner'
'Marz'

we want to replcae this ä with a without any other logic. Is there any other method available in Intl.DateTimeFormat to achieve this behaviour?

depperm
  • 10,606
  • 4
  • 43
  • 67
Harsh Shah
  • 41
  • 4
  • 1
    Is there any official standard behind the conversion from `Jänner` -> `Jannar`? Does `Jannar` really exist as an official alternative to `Jänner`? – t.niese Aug 12 '21 at 11:53
  • There is no such thing as a "no diacritics" variant of locales. You'll have the same issue with `März` in plain German. As it happens, `ä` is the only character to change, both in Austrian and German, so the current answer is probably the simplest that does the job. If you want to remove all diacritics, you can use `str.normalize("NFD").replace(/[\u0300-\u036f]/g, "")` as explained [here](https://stackoverflow.com/a/37511463/2960823). – kuroi neko Aug 13 '21 at 07:31

1 Answers1

1

If you just want the spelling to be changed you can use replace

var date = new Date(Date.UTC(2020, 0, 20, 3, 23, 16, 738));
console.log(new Intl.DateTimeFormat('de-at', { month: 'long' }).format(date).replace('ä','a'));
date = new Date(Date.UTC(2020, 2, 20, 3, 23, 16, 738));
console.log(new Intl.DateTimeFormat('de-at', { month: 'long' }).format(date).replace('ä','a'));
depperm
  • 10,606
  • 4
  • 43
  • 67