Files
30-seconds-of-code/snippets/toEnglishDate.md
Angelos Chalaris b74eb9d9bd Linting
2017-12-27 11:02:46 +02:00

445 B

toEnglishDate

Converts a date from American format to English format.

Use Date.toISOString(), split('T') and replace() to convert a date from American format to the English format. Throws an error if the passed time cannot be converted to a date.

const toEnglishDate = (time) => { try { return new Date(time).toISOString().split('T')[0].replace(/-/g, '/'); } catch (e) {} };
// toEnglishDate('09/21/2010') -> '21/09/2010'