نمایش مقدار زمان باقیمانده تا یک وقت روزانه (با javascipt)
این کد برای نمایش تعداد ساعت باقیمانده تا یک وقت روزانه به کار می رود :
کدها :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function doFormalTime() {
var myTime = new Date();
var myHour = myTime.getHours();
var myMinutes = myTime.getMinutes();
var ampm = " in the morning.";
if (myHour >= 12) {
myHour -= 12; // change to PM
ampm = "pm";
}
Hour = new Array(
"One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Eleven", "Twelve");
// gets nearest 5 minutes
myMin = myMinutes - (myMinutes % 5);
// closer to next 5 minutes, go to next
if (myMinutes % 5 > 2) myMin += 5;
var text = "It is now about ";
switch(myMin) {
case 0 : myHour--; break;
case 5 : text += "five after "; myHour--; break;
case 10 : text += "ten after "; myHour--; break;
case 15 : text += "quarter after "; myHour--; break;
case 20 : text += "twenty after "; myHour--; break;
case 25 : text += "twenty-five after "; myHour--; break;
case 30 : text += "half past "; myHour--; break;
case 35 : text += "twenty-five till "; break;
case 40 : text += "twenty till "; break;
case 45 : text += "quarter till "; break;
case 50 : text += "ten till "; break;
case 55 : text += "five till "; break;
case 60 : break;
}
if (myHour < 1) myHour++; // fix for noon/midnight
if (ampm == "pm") {
ampm = (myHour >= 4) ? " in the evening." : " in the afternoon.";
}
text += Hour[myHour] + ampm;
return text;
}
</script>
</head>
<body>
<center>
<script>
document.write(doFormalTime());
</script>
</center>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function doFormalTime() {
var myTime = new Date();
var myHour = myTime.getHours();
var myMinutes = myTime.getMinutes();
var ampm = " in the morning.";
if (myHour >= 12) {
myHour -= 12; // change to PM
ampm = "pm";
}
Hour = new Array(
"One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Eleven", "Twelve");
// gets nearest 5 minutes
myMin = myMinutes - (myMinutes % 5);
// closer to next 5 minutes, go to next
if (myMinutes % 5 > 2) myMin += 5;
var text = "It is now about ";
switch(myMin) {
case 0 : myHour--; break;
case 5 : text += "five after "; myHour--; break;
case 10 : text += "ten after "; myHour--; break;
case 15 : text += "quarter after "; myHour--; break;
case 20 : text += "twenty after "; myHour--; break;
case 25 : text += "twenty-five after "; myHour--; break;
case 30 : text += "half past "; myHour--; break;
case 35 : text += "twenty-five till "; break;
case 40 : text += "twenty till "; break;
case 45 : text += "quarter till "; break;
case 50 : text += "ten till "; break;
case 55 : text += "five till "; break;
case 60 : break;
}
if (myHour < 1) myHour++; // fix for noon/midnight
if (ampm == "pm") {
ampm = (myHour >= 4) ? " in the evening." : " in the afternoon.";
}
text += Hour[myHour] + ampm;
return text;
}
</script>
</head>
<body>
<center>
<script>
document.write(doFormalTime());
</script>
</center>
</body>
</html>
دسته بندی
کدهای آماده برای زمان و تاریخ
نظرات 0 0 0