|
แสดงเวลาแบบ คือ Military TIME และ 12 Hour
|
| เขียนโดย
Poj
,
27-12-2007
|
|
|
แสดงเวลา แบบ คือ MILITARY TIME และแบบ 12 Hour ครับ ดูตัวอย่างได้ ที่นี่
1.นำโค้ดนี้ไปใส่ไว้ใน <head>....</head> ครับ
| <script LANGUAGE="JavaScript"> <!-- Begin function showMilitaryTime() { if (document.form.showMilitary[0].checked) { return true; } return false; } function showTheHours(theHour) { if (showMilitaryTime() || (theHour > 0 && theHour < 13)) { return (theHour); } if (theHour == 0) { return (12); } return (theHour-12); } function showZeroFilled(inValue) { if (inValue > 9) { return "" + inValue; } return "0" + inValue; } function showAmPm() { if (showMilitaryTime()) { return (""); } if (now.getHours() < 12) { return (" AM"); } return (" PM"); } function showTheTime() { now = new Date document.form.showTime.value = showTheHours(now.getHours()) + ":" + showZeroFilled(now.getMinutes()) + ":" + showZeroFilled(now.getSeconds()) + showAmPm() setTimeout("showTheTime()",1000) } // End --> </script> |
2.นำโค้ดนี้ไปใส่ไว้ใน <body>....</body> ครับ
<font face="MS Sans Serif" size="1"> <form name="form"> <input type="text" name="showTime" size="11" style="text-align: Center"><br> <input type="radio" name="showMilitary" checked> ดูแบบ MILITARY TIME<br> <input type="radio" name="showMilitary"> ดูแบบ 12 HOUR TIME </form> </font> |
3.เพิ่มโค้ดเช้าไปที่ <body> ครับ
| <body onLoad="showTheTime()"> |
Credit: codetukyang
|
|
<- Back | Next ->
|
|