I want to know the date format that is using the current device, for example, is I call this function, this function will return me the current format
var a = getDateFormat();
console.log(a);
MM/dd/YYYY
Anyone know how to archive that?
I want to know the date format that is using the current device, for example, is I call this function, this function will return me the current format
var a = getDateFormat();
console.log(a);
MM/dd/YYYY
Anyone know how to archive that?
There is currently no cross platform way in Electron to get the users preferred date format or decimal separator. You can guess users preference by looking at the response of app.getLocale()
but you'll still find somebody who has overridden their systems local regional settings with their preferences.
Workaround to get system date format: https://github.com/electron/electron/issues/13023#issuecomment-418581463
(Tested on Windows 10)
Date format depends on localization setting. In electron you can use app.getLocale() to obtain locale string.
To get date format string (which should be well defined for locales), you can either create the mapping on your own or try to use some external libraries that already have that information. Moment.js can be useful, you can get dateFormat info from it (and also format date if that is your final goal).
Check this fiddle to see how to get longDateFormat using locale string.
let l = moment().locale('en');
console.log(l.localeData().longDateFormat('L'));
l = moment().locale('es');
console.log(l.localeData().longDateFormat('L'));