zoukankan      html  css  js  c++  java
  • 将系统时间转换为汉字表示的四种方法

    <!-- 重点:学习Date对象的方法和js基础逻辑. -->

     1 <!DOCTYPE html>
     2 <html lang="en">
     3   <head>
     4     <meta charset="UTF-8">
     5     <title>时间</title>
     6     <script type="text/javascript"> 
     7     function curTime()
     8     {
     9       var time = new Date();
    10       var year = time.getFullYear();
    11       var mouth = time.getMonth();
    12       var day = time.getDate();
    13       var hour = time.getHours();
    14       var minute = time.getMinutes();
    15       var second = time.getSeconds();
    16       var week = time.getDay();
    17       //将系统星期转换为中文星期
    18       //第一种,借用数组方法
    19       var    weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    20       //使用if+else判断
    21       var day1;
    22       if(week == 0){
    23         day1 = "星期日";
    24       }else if(week == 1){
    25         day1 = "星期一";
    26       }else if(week == 2){
    27         day1 = "星期二";
    28       }else if(week == 3){
    29         day1 = "星期三";
    30       }else if(week == 4){
    31         day1 = "星期四";
    32       }else if(week == 5){
    33         day1 = "星期五";
    34       }else{
    35         day1 = "星期六";
    36       }
    37 
    38       //使用switch+case判断
    39       var day2;
    40       switch(week){
    41         case 0:
    42           day2 = "星期日";
    43           break;
    44         case 1:
    45           day2 = "星期一";
    46           break;
    47         case 2:
    48           day2 = "星期二";
    49           break;
    50         case 3:
    51           day2 = "星期三";
    52           break;
    53         case 4:
    54           day2 = "星期四";
    55           break;
    56         case 5:
    57           day2 = "星期五";
    58           break;
    59         default:
    60           day2 = "星期六";    
    61       }
    62 
    63       //使用charat()函数
    64       var day3 = "星期" + "日一二三四五六".charAt(time.getDay());
    65 
    66       var cur =year + "/" + mouth + "/" + day + " " + hour + ":" + minute + ":" + second + " " + day3;
    67 
    68       var times = document.getElementById("times");
    69       times.innerHTML = cur;
    70     }
    71 
    72     setInterval(curTime,1000);
    73     </script>
    74   </head>
    75   <body>
    76     <div id=times>
    77     </div>
    78   </body>
    79 </html>
  • 相关阅读:
    AX 2012 Security Framework
    The new concept 'Model' in AX 2012
    How to debug the SSRS report in AX 2012
    Using The 'Report Data Provider' As The Data Source For AX 2012 SSRS Report
    Deploy SSRS Report In AX 2012
    AX 2012 SSRS Report Data Source Type
    《Taurus Database: How to be Fast, Available, and Frugal in the Cloud》阅读笔记
    图分析理论 大纲小结
    一文快速了解Posix IO 缓冲
    #转载备忘# Linux程序调试工具
  • 原文地址:https://www.cnblogs.com/zou-zou/p/8569604.html
Copyright © 2011-2022 走看看