Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localized format without the day

Tags:

dayjs

Is there any way to get a localized format in DayJS plugin but without the day? I need to show in a calendar the month and year only but depending on the locale, the month can be on the first place or at the end.

I've checked in the docs (https://day.js.org/docs/en/display/format#localized-formats) but it seems there is nothing with year and month only.

dayjs().format("LL") // December 7, 2022
// what I would like to get: December 2022 or 2022 December (depending on the locale)

Thanks in advance

like image 939
Proz1g Avatar asked Nov 27 '25 04:11

Proz1g


1 Answers

I end up using a regex to delete the part I didn't want.

dayjs().format("LL").replace(/\b\s*\d{1,2}\s*\b/g, '');

DEMO:

["December 7, 2022", "7 Décembre 2022"].map(date => console.log(date.replaceAll(/\b\s*\d{1,2}\s*\b/g, '')));
like image 140
Maxime Lechevallier Avatar answered Nov 29 '25 23:11

Maxime Lechevallier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!