I was writting unit test today for this function:
/**
* recives a timestamp and format to 'yyyy/mm/dd hh:mm'
*/
function formatCurrentDate(date) {
return Intl.DateTimeFormat('ja-JP',
{
hour: '2-digit',
minute: '2-digit',
year: 'numeric',
month: '2-digit',
day: '2-digit'
}).format(date);
}
with this test:
test('it should format the current date', () => {
expect(formatCurrentDate(new Date().getTime())).toMatch(new RegExp(/^\d{4}\/\d{2}\/\d{2}\s{1}\d{2}\:\d{2}$/));
});
but always is failing because the node returns to me a different date format
so i just realized runnig formatCurrentDate() on devtools i got the correct format: '2020/08/25 14:50'
but when i run the same funciton on my cmd (typing node and pasting the function) i got: '2020-08-25 14:50'
why is this happening??