Edward Edward -4 years ago 142
Javascript Question

How to get month from string in javascript?

I have tried

var d=new Date("2012-07-01 00:00:00.0");

But getting

I want month as
for the above date.

Answer Source

Assuming your date is in YYYY-MM-DD format

var arr = "2012-07-01 00:00:00.0".split("-");
var months = [ "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December" ];
console.log("The current month is " + months[parseInt(arr[1],10)])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download