0

i have a datetime parameter in a string from an JSON object

like this-

        datetime:"2015-04-15 09.00.00"

my goal is to convert it to:

        "15 April 09:00" 

(2015 can be included as well but not necessary) After i will append in in 2 different places, date and time.

Any suggestions? Can't seem to find any good info apart from getting a plugin.

  • I use moment for this kind of stuff, it supports almost everything I throw at it. http://momentjs.com/ – loddn Apr 14 '15 at 07:49

1 Answers1

2

You can parse the month like the answer here:

https://stackoverflow.com/a/1643468/2498251

var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];

so for your case you can make something like this:

var d = new Date("2015-04-15 09:00:00");
var day = d.getDay();
var month = monthNames[d.getMonth()];
var year = d.getYear();
var hour = d.getHours();
var min = d.getMinutes();

var fullDatetime = day + ' ' + month + ' ' + hour + ':' + min;
Community
  • 1
  • 1
Elad
  • 891
  • 5
  • 15