-1

Does Javascript not have any built in support for formatting dates? I have a date object, and I want to format it to a format of my choice e.g. the date that I want to convert is '2017-12-22'. Is there not any function that I could use

something like var newFormattedDate = new Date('2017-12-22', 'mm/dd/yyyy')

so that the output is 22/12/2017

Rafey Hijazy
  • 121
  • 1
  • 5

1 Answers1

1

Javascript doesn't have support to give format to date. You can use moment.js.

Alternatively, you can use string#replace.

console.log('2017-12-22'.replace(/(....)-(..)-(..)/g,'$3/$2/$1'));
Aarif Aslam
  • 1,077
  • 10
  • 15