Files
30-seconds-of-code/snippets/to-english-date.md
Stefan Feješ b848906fe5 fix naming
2017-12-17 15:41:31 +01:00

394 B

Convert to English date

Use Date.toISOString(), split('T') and replace() to convert a date from American format to 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){return}};
// toEnglishDate('09/21/2010') -> '21/09/2010'