zoukankan      html  css  js  c++  java
  • 根据12和24小时制选择不同的时间显示

    <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>

  • 相关阅读:
    Spring框架构造注入的属性问题type属性
    Spring框架AOP添加日志记录功能
    Spring框架构造注入
    Spring框架AOP原理
    Spring框架构造注入的顺序问题index属性
    Spring框架使用P命名空间进行注入
    工作中的SQL脚本
    spring框架ioc设置注入小demo
    [笔试] C和C++动态内存分配和释放的区别
    [算法] 当今世界最为经典的十大算法投票进行时
  • 原文地址:https://www.cnblogs.com/gwq369/p/5509143.html
Copyright © 2011-2022 走看看