Javascript Data Type How to - Get day of week string








Question

We would like to know how to get day of week string.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--from   ww w . j  a va2s  . c o  m-->
    var d = new Date("2014-09-01"); 
    var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    document.writeln(d);
    document.writeln("<br/>");
    d.setTime( d.getTime() + d.getTimezoneOffset()*60000 ); 
    document.writeln(d);
    document.writeln("<br/>");
    document.writeln( days[d.getDay()] )
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: