-1

If I post there, it's after research that didn't get answers. Here's my problem :

I would like to display on the html the Date() in the format JavaScript use it. If I run this : something.innerHTML = new Date(); I'll obtain "Mon Mar 05 2018 18:13:35 GMT+0100 (Paris, Madrid)". However if I run this : console.log(new Date()); It will give me "2018-03-05T17:15:05.795Z" which is how JavaScript use it in his execution (If I'm right) and what I want to get in the html.

Hopping it was understandable, to resume : how to get "2018-03-05T17:15:05.795Z" (used by js in execution) displaying on html instead of "Mon Mar 05 2018 18:13:35 GMT+0100 (Paris, Madrid)" ?

Thank you very much for any answers, have a nice day :) - GreenData

GreenData
  • 13
  • 3
  • 1
    "which is how JavaScript use it in his execution"...no, that's just another string format of the date. `Date` doesn't use any kind of string internally. It uses the individual numeric values such as day, month, year etc. to do calculations. Anyway if you want to get the date string in a different format, you can see all the possible options by reading the documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date . If none of the shorthand methods suit you, you can build your own format string longhand using the "getDate", "getMonth" etc strings. – ADyson Mar 05 '18 at 17:21
  • 1
    The latter is the result of .toISOString(), the former .toString() – Alex K. Mar 05 '18 at 17:24

2 Answers2

2

You can just use toISOString() like:

something.innerHTML = new Date().toISOString();
palaѕн
  • 72,112
  • 17
  • 116
  • 136
1

You can try toISOString()

document.getElementById('showDate').innerHTML = new Date().toISOString();
<div id="showDate"></div>
brk
  • 48,835
  • 10
  • 56
  • 78