Javascript Data Type How to - Get day month and year from 'Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)'








Question

We would like to know how to get day month and year from 'Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)'.

Answer


<!DOCTYPE html>
<html>
<head>
<!--from   w ww.j  av  a2  s.  c om-->
<script type='text/javascript'>

var d = new Date("Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)");
var weekday=["Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
document.writeln('Month : ' + month[d.getMonth()] + ' and Day : ' + weekday[d.getDay()]);

</script>
</head>
<body>

</body>
</html>

The code above is rendered as follows: