Lets consider the following code:
console.log(new Intl.DateTimeFormat('pl-PL', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
}).format(new Date(2019, 2, 4)));
In Node JS
it gives 2019-03-04
but in chrome browser
it returns 04.03.2019
.
Why?
My question is similar to:
Why Intl.DateTimeFormat produces different result in different browsers?
Where is official documentation for node and chrome and when can I read about these differencies.
Update:
It can be helpful for someone so I will add that to enforce common format I am using this code:
export const useDashInDate = (dateString: string): string => {
return /\d{4}-\d{2}-\d{2}/.test(dateString) ? dateString : dateString.split('.').reverse().join('-');
};