Here we are going to know how to display current time and date using javascript in Jsp or Html pages.
Quote:<div class="form">
<span id="my_clock"></span>
</div>
<script type="text/javascript">
function startclock()
{
var thetime=new Date();
var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var nday=thetime.getDay();
var nmonth=thetime.getMonth();
var ntoday=thetime.getDate();
var nyear=thetime.getYear();
var AorP = (nhours >= 12) ? "P.M." : "A.M.";
if (nhours>=13)
nhours-=12;
if (nhours99) && (nyear<2000))
nyear+=1900;
var clock_span = document.getElementById("my_clock"); clock_span.innerHTML = nhours+":"+nmins+":"+nsecn+" "+AorP+" "+nday+", "+nmonth+"/"+ntoday+"/"+nyear;
setTimeout('startclock()',1000);
}
if (document.getElementById && document.createTextNode)
{
startclock();
}
</script>
You may save this file seperately as "filename.jsp" and use <jsp:include page="filename.jsp"/>to view time in jsp page or use the script inside jsp page as well. Normally use script and jsp seperately to find bug easily. You can use this script in any language like php,.net etc.
Happy Coding