8

I have date in ISO-format like:

2016-02-17T16:40:30

How can I convert it to a human-readable date, for example:

17 Feb 2016 16:40
Maccath
  • 3,936
  • 4
  • 28
  • 42
yoram
  • 191
  • 1
  • 1
  • 13

1 Answers1

28

First of all, you need to create a date using your original date string.

var d = new Date('2016-02-17T16:40:30');

And then you can use this to fetch a readable date format:

d.toDateString();

Will return:

Wed Feb 17 2016

Maccath
  • 3,936
  • 4
  • 28
  • 42
  • but I lost the time in this way – yoram Feb 23 '16 at 12:49
  • 3
    You can use `d.toUTCString()` instead, or a combination of functions like `d.getUTCHours()` and `d.getUTCMinutes()` to construct your own string. – Maccath Feb 23 '16 at 12:51
  • There is also [`toLocaleDateString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) if you wanted localized output. – davidmyersdev Jul 09 '23 at 19:36