Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sinnbeck's avatar
Level 102

Flatpickr static methods - locale

Flatpickr has a few nice build in static methods to format dates https://flatpickr.js.org/instance-methods-properties-elements/#useful-static-methods

Sadly I cannot get those to work with locale. I always get the english (default version).

import flatpickr from 'flatpickr'
import {Danish} from 'flatpickr/dist/l10n/da.js'

flatpickr.localize(flatpickr.l10ns.da)
//I have also tried with 
flatpickr.localize(Danish)

console.log(flatpickr.formatDate(new Date(2022, 06, 03), 'F j, Y'))

I have also made a simple jsfiddle with the problem. The formatted date should be "Juli 3. 2022" https://jsfiddle.net/48mrjs60/

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@sinnbeck this worked for me:

console.log(flatpickr.formatDate(new Date(2022, 06, 03), 'F j, Y', flatpickr.l10ns.da))

passing the locale as third param on the formatDate function, and I had to add the import

<script src="https://npmcdn.com/flatpickr/dist/l10n/da.js"></script>

not sure why the global one does not work, at least not in JSFiddle.

Sinnbeck's avatar
Level 102

@Nakov Doh why didnt I just try that. I just trusted the API :D Thanks you!

1 like

Please or to participate in this conversation.