แสดงวัน และ เวลาในเว็บเพจของเรา

Time: Date:
วิธีการแทรกวัน เวลาลงในเว็บเพจ
  ท่านได้ทราบแล้วว่า html นั้นประกอบด้วย ส่วนที่เป็น head และ ส่วนที่เป็น body ในที่นี้เราจะทำการแทรกสคริปส์ไว้ 3 ที่ด้วยกันดังนี้

<HTML>
<HEAD>
<SCRIPT LANGUAGE= "JavaScript">

//Actually display the time
function showDateTime() {
var now = new Date();
//variables for date
var date = now.getDate();
var month = now.getMonth()+1;
var year = now.getYear();
var dateValue = "" + month;
dateValue += ((date < 10) ? "/0": "/") + date;
dateValue += "/" + year;
document.DateTime.Date.value = dateValue;

//variables for time
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeValue = "" + (( hours > 12 ) ? hours -12 : hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") +seconds
timeValue += ( hours >= 12) ? " P.M. " : " A.M. "
document.DateTime.Time.value = timeValue

//you could replace the above with this
//and have a clock on the status bar:
//window.status = timeValue;
setTimeout("showDateTime()", 1000);
}
</SCRIPT>

</HEAD>
<BODY onLoad="showDateTime()">
<FORM NAME = "DateTime">
Time:<INPUT TYPE="text" NAME = "Time" SIZE = 12 VALUE = "">
Date:<INPUT TYPE="text" NAME = "Date" SIZE = 10 VALUE = "">
</FORM>

</BODY>
</HTML>

Power By : khonkaenlik.com