Wednesday 29 April 2009

Javascript Function to Return the Day of the Year

This simple Javascript function returns the day of the year.

<html>

<head>

<script type="text/javascript">

function dayOfYear()
{
var firstJan = Math.floor((new Date().setFullYear(new Date().getFullYear(),0,1))/86400000);
var today = Math.ceil((new Date().getTime())/86400000);
return(today-firstJan);
}

</script>

</head>

<body>

<h1>Day of Year</h1>

Today is day <script type="text/javascript">document.write(dayOfYear());</script> of the year.

</body>

</html>

Today is day of the year.

No comments: