Added localized date formatting function
This commit is contained in:
parent
8b378a548d
commit
009ec66c10
|
@ -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'
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user