Monday, February 11, 2013

JavaScript program to display todays date


<!--fms-->
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>JavaScript to display date</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

jsp to display todays day of the week


<!--fms-->
<html>
<body>

<p id="demo">Click the button to display todays day of the week.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Today is Sunday";
weekday[1]="Today is Monday";
weekday[2]="Today is Tuesday";
weekday[3]="Today is Wednesday";
weekday[4]="Today is Thursday";
weekday[5]="Today is Friday";
weekday[6]="Today is Saturday";

var x = document.getElementById("demo");
x.innerHTML=weekday[d.getDay()];
}
</script>

</body>
</html>

Sunday, February 10, 2013

jsp program to display clock


<!jsp program to display clock!>
<!DOCTYPE html>
<html>
<head>
<script>
function startTime()
{
  var today=new Date();
  var h=today.getHours();
  var m=today.getMinutes();
  var s=today.getSeconds();
  // add a zero in front of numbers<10
  m=checkTime(m);
  s=checkTime(s);
  document.getElementById('txt').innerHTML=h+":"+m+":"+s;
  t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
   if (i<10)
   {
      i="0" + i;
   }
   return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>