javascrpit中24小时制转为12小时制代码

<!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>
    <title>convet_24h_to_12h</title>
    <!--引用公共的js文件-->
    <script type="text/javascript">
    var date = new Date();
    var hour = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    hour=fixHours(hour);
    minutes = fixMinutes(minutes);
    seconds = fixSeconds(seconds);
    var date_time_string = "The time is now "+hour+":"+minutes+":"+seconds;
     function fixHours(number)
     {
       if(number>12)
       {number=number%12;
         number=number+".PM";
       }
       else{
        number = number +".AM";
       }
       return number;
     }
     function fixMinutes(number)
     {
        if(number<10)
        {
          number="0"+number;
        }
        return number;
      }
      function fixSeconds(number)
     {
        if(number<10)
        {
          number="0"+number;
        }
        return number;
      }
    
   
    </script>
</head>
<body>
<script type="text/javascript">
 document.write(date_time_string);
</script>


</body>
</html>

你可能感兴趣的:(html,Date,XHTML,String,function)