Added localized date formatting function

This commit is contained in:
PMKuipers 2023-07-28 23:42:57 +02:00
parent 8b378a548d
commit 009ec66c10

View File

@ -54,4 +54,22 @@ export function load_stringkeys(string_keys){
} }
return string_keys; return string_keys;
} }
/**
* Format a date according to localized custom
* @param {Date|string} d The date to convert
* @param {boolean} short Short format (default false)
* @returns {string}
*/
export function format_date(d,short){
if(!(d instanceof Date)){
d = new Date(d);
}
let monthformat = "short";
if(short){
monthformat = "numeric";
}
return d.toLocaleDateString(document.documentElement.lang,{
year: 'numeric', month: monthformat, day: 'numeric'
});
}