0

I have a string "2016-01-01T00:20:50z". How can I parse the string into date and time format in Javascript? Such as for string date: "2016-01-01" and for string time format: "20:50".

Thank you

  • 3
    Possible duplicate of [Help parsing ISO 8601 date in Javascript](http://stackoverflow.com/questions/4829569/help-parsing-iso-8601-date-in-javascript) – Michał Perłakowski Sep 27 '16 at 21:42
  • Follow this link http://stackoverflow.com/questions/5619202/converting-string-to-date-in-js – Gangz Sep 27 '16 at 21:47
  • @Gangz but doing new Date('2011-04-11T10:20:30Z'), what would it return? It would be one string again and needs to be parsed to date and time format again? –  Sep 27 '16 at 22:16

1 Answers1

0

I would highly recommend Datejs at "https://github.com/datejs/Datejs" for all things dealing with date and time. It can parse "2016-01-01T00:20:50Z" correctly (note the "z" has to be capital.)

Michael Erickson
  • 4,217
  • 2
  • 23
  • 10
  • not saying you are wrong, but https://github.com/moment/moment/ is used more often and is proven. Check it out. – Derek Pollard Sep 27 '16 at 21:48
  • 1
    @MichaelErickson Is there way to do with just with Javscript rather than using a framework? –  Sep 27 '16 at 22:13
  • @You I looked into moment js and looks useful, but I can't seem to find the exact example for my case. How would I parse string "2016-01-01T00:20:50z" into date: "2016-01-01" and time: "20:50" –  Sep 27 '16 at 22:21