根据12和24小时制选择不同的时间显示
2016-05-19 16:30
501 查看
<HTML>
<HEAD>
<TITLE>时间日期篇--当前时间</TITLE>
<meta charset="utf-8">
</HEAD>
<BODY bgcolor="#fef4d2" onLoad=showTheCurrentTime()>
<br>
<br>
<center>
<font color="ffaafa"><h2>时间日期篇--当前时间</h2></font>
<hr width=300>
<br>
<br>
<!-- 案例代码1开始 -->
<script type="text/javascript">
function showMilitaryTime() {
if (document.form.showMilitary[0].checked) {
return true;
}
return false;
}
//showTheHours解决小时的问题
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 showTheCurrentTime() {
now = new Date
document.form.showTime.value = showTheHours(now.getHours()) + ":" + showZeroFilled(now.getMinutes()) + ":" + showZeroFilled(now.getSeconds()) + showAmPm()
setTimeout("showTheCurrentTime()",1000)
}
</script>
<!-- 案例代码1结束 -->
<!-- 案例代码2开始 -->
<form name="form">
<div align="center">
<center>
<p>
<font> <!-- [Step1]: 这里可以改变显示列的长度 --> <input type="text"
name="showTime" size="11">
</font>
</p>
</center>
</div>
<div align="center">
<center>
<p>
<input type="radio" name="showMilitary" checked> <font
color="">24 Hour Time<br> <input type="radio"
name="showMilitary"> 12 Hour Time<br>
</font>
</p>
</center>
</div>
</form>
<!--案例代码2结束 -->
</center>
</BODY>
</HTML>
<HEAD>
<TITLE>时间日期篇--当前时间</TITLE>
<meta charset="utf-8">
</HEAD>
<BODY bgcolor="#fef4d2" onLoad=showTheCurrentTime()>
<br>
<br>
<center>
<font color="ffaafa"><h2>时间日期篇--当前时间</h2></font>
<hr width=300>
<br>
<br>
<!-- 案例代码1开始 -->
<script type="text/javascript">
function showMilitaryTime() {
if (document.form.showMilitary[0].checked) {
return true;
}
return false;
}
//showTheHours解决小时的问题
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 showTheCurrentTime() {
now = new Date
document.form.showTime.value = showTheHours(now.getHours()) + ":" + showZeroFilled(now.getMinutes()) + ":" + showZeroFilled(now.getSeconds()) + showAmPm()
setTimeout("showTheCurrentTime()",1000)
}
</script>
<!-- 案例代码1结束 -->
<!-- 案例代码2开始 -->
<form name="form">
<div align="center">
<center>
<p>
<font> <!-- [Step1]: 这里可以改变显示列的长度 --> <input type="text"
name="showTime" size="11">
</font>
</p>
</center>
</div>
<div align="center">
<center>
<p>
<input type="radio" name="showMilitary" checked> <font
color="">24 Hour Time<br> <input type="radio"
name="showMilitary"> 12 Hour Time<br>
</font>
</p>
</center>
</div>
</form>
<!--案例代码2结束 -->
</center>
</BODY>
</HTML>
相关文章推荐
- 避免使用非静态内部类,这会导致Context泄露
- tupian
- PXE+HTTP+TFP+DHCP自动化部署
- Java关系操作符简写介绍
- 2.NSBundle
- 一步一步地配置Spring
- AsyncTask params java.lang.ArrayIndexOutOfBoundsException: length=0; index=0异常
- SharePreference的简单用法
- 多线程变量 pthread_key_t 自查文档
- 欢迎使用CSDN-markdown编辑器
- android listview 连续调用getview问题分析及解决
- Android 4.0 事件输入(Event Input)系统
- 【Maven】maven的常用命令以及搭建maven私人仓库
- GeekBand第二周 ListView(上)
- SM2算法第十四篇:ECDH秘钥交换的C程序
- SHELL跳出循环、shift左移、函数的使用和数据库自动备份脚本
- Ruby程序中正则表达式的基本使用教程
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
- [Book Note] Haskell: Monad
- WebSphere MQ简单的命令行操作