0

How do I convert:

Wed Jan 10 2018 14:40:39 GMT+0100 (Paris, Madrid)

to

10/01/2018

in javascript?

Chayma Atallah
  • 647
  • 1
  • 9
  • 27

1 Answers1

0

console.log(new Date().toLocaleDateString());

Will give you the result you want

Satpal
  • 126,885
  • 12
  • 146
  • 163
Gianluca Paris
  • 1,166
  • 1
  • 12
  • 24
  • This doesn't solve the question: Try this: `var d = new Date("Wed Jan 10 2018 14:40:39 GMT+0100 (Paris, Madrid)"); d = d.getDate() + '/' + (1 + d.getMonth()) + '/' + d.getFullYear();` JSfiddle: https://jsfiddle.net/r1mb2dub/ – Kent V Jan 10 '18 at 13:59
  • He wrote he obtained that string doing new Date(), so this solves the question – Gianluca Paris Jan 10 '18 at 14:39
  • He wants it to be `10/01/2018` . Your code will make it to be `01/10/2018` (MM/DD/YYYY). – Kent V Jan 10 '18 at 14:45
  • Your fiddle gives exactly 10/1/2018 – Gianluca Paris Jan 10 '18 at 14:50
  • The format of [*toLocaleString*](http://ecma-international.org/ecma-262/8.0/#sec-date.prototype.tojson) is implementation dependent. Whether the value returned by a particular browser matches the OP's format is just luck. For me, the answer gives "1/10/2018", which is not the format used locally, nor does it match the OP. – RobG Jan 10 '18 at 20:18