HTML code for time stamp
Hi Marvin,
You cannot create any dynamic web page using HTML because it is used for formatting web pages.
For displaying the current time stamp you need to use any scripting language like javascript or vbscript.
Vbscript code
<html>
<script type=”text/vbscript”>
Function Displaydatetime()
Frmtimestamp.txtdate.text=FormatDateTime(Date, 0);
Frmtimestamp.txtdate.text= Frmtimestamp.txtdate.text & FormatDateTime(Time,3);
End Function
</script>
<body onload=”Displaydatetime()”>
<form name=”frmtimestamp”>
<input type=”text” name=”txtdatetime”>
</form>
</body>
</html>
Syntax:
FormatDateTime(dateOrTime, format)
The dateOrTime parameter is the date or time you want to format, and the format parameter is the type of formatting to apply.The format parameter can take a value from 0 – 4, each value signifying a different type of formatting:
0 (used for dates) – display a date in the format mm/dd/yy (default)
1 (used for dates) – display a date in the format day, month and month day, year
2 (used for dates) – display a date in the format mm/dd/yy (default (same as 0))
3 (used for time) – display time in the format hh:mm:ss: PM/AM (12 hour format)
4 (used for time) – display time in the format hh:mm (24 hour format)
Javascript Code
<html>
<script type=”text/javascript”>
function Displaydatetime()
{
var tsDate=new Date();
var date=ts.getDate();
var month=ts.getMonth()+1;
var year=ts.getFullYear();
var hours=ts.getHours();
var minutes=ts.getMinutes();
var seconds=ts.getSeconds();
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours – 12;
}
if (hours == 0) {
hours = 12;
}
Frmtimestamp.txtdate.text= date + "/" + month + "/" + year ;
Frmtimestamp.txtdate.text= Frmtimestamp.txtdate.text + hours + " : " + minutes + " : " + seconds + suffix;
}
</script>
<body onload=”Displaydatetime()”>
<form name=”frmtimestamp”>
<input type=”text” name=”txtdatetime”>
</form>
</body>
</html>
In javascript whenever you write new Date() it shows the current date in standard format with Current day,date,time and GMT.You can have your own format.
eg:suppose today is 12-05-2012 then
getDate() shows current date(eg: 12)
getMonth() shows current month (eg: 5)
getFullYear() shows current year as 2012.
getHours() shows current hours in 24 hrs format.
getMinutes() shows current minutes.
getSeconds() shows current seconds
After getting date ,month ,year and time you can print these according to desired format.