-1

Datetime has format like this: var datetime = "2015-10-19T22:50:00.000+02:00"

How can I convert it to 19 Oct, 2015 ?

Thank you so much

Hai Tien
  • 2,929
  • 7
  • 36
  • 55
  • 2
    This question really shows that no attempt was made at all to research this – charlietfl Oct 20 '15 at 17:44
  • 1
    `new Date("2015-10-19T22:50:00.000+02:00").toUTCString().split(" ").slice(1,4).join(" ")` – dandavis Oct 20 '15 at 17:45
  • 1
    In pure JS is a long answer, but you should look at [moment.js](http://momentjs.com/) for a solid library to handle dates. – 1cgonza Oct 20 '15 at 17:47
  • @1cgonza: isn't moment a lot longer than calling a few methods? last i checked it was dozens of KBs... Moment is good for somethings, especially parsing, but date formatting in vanilla is not as bad as people make it out to be... – dandavis Oct 20 '15 at 17:48
  • Thank all but I need fast solution. Thank so much !!!!! – Hai Tien Oct 20 '15 at 17:51
  • @dandavis depends… does OP want the output in local timezone, UTC, …? can't really extrapolate from a single example and no intentional description of what he wants. Moment is tens of kb but that may be worth the convenience of having a reliable, easy-to-use library. – Touffy Oct 20 '15 at 17:51
  • @Touffy: that's all true enough, i just find that whipping up a custom date formatter never takes me more than a few lines of vanilla. i think people look at crappy methods like .getHours() and freak out, instead of using a timezoneoffset-adjust UTC flavor to get the date parts, or replace()ing an existing standard string output into the format they need... – dandavis Oct 20 '15 at 17:58
  • Possible duplicate of [How can I convert string to datetime with format specification in JavaScript?](http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript) – Vladimir Petrakovich Oct 20 '15 at 18:24

1 Answers1

2
var datetime = "2015-10-19T22:50:00.000+02:00"
new Date(datetime).toDateString()
Touffy
  • 6,309
  • 22
  • 28