2014-03-12 27 views
0

我想把這個軍事時鐘轉換爲標準時間。我是新手(只是學習)如何編碼電腦,不知道該怎麼做。網站,資源,想法將不勝感激。 謝謝!Javascript:從軍事轉換到標準時間

<?xml version="1.0" encoding="ISO-8859-1"?> 
    <!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>Digital Clock</title> 
    <script type="text/javascript"> 
    <!-- 
    // this function actually updates the clock display. It will be called 
    // every second provided by the setInterval() call in the document body 
    function updateClock() 
    { 
    var time = new Date();    // create a new time stamp 
    var hours = time.getHours();  // retrieve hours from the time stamp 
    hours = format(hours);    // ... and format them 

    var minutes = time.getMinutes(); // retrieve minutes from the time stamp 
    minutes = format(minutes);   // ... and format them 

    var seconds = time.getSeconds(); // retrieve seconds from the time stamp 
    seconds = format(seconds);   // ... and format them 

    // update the text field (the top clock) 
    document.clock.display.value = hours + ":" + minutes + ":" 
    + seconds;     

    // update the button text (the bottom clock) 
    document.clock.display2.value = hours + ":" + minutes; 
    } 

// this function adds a leading zero to the number if it is below 10 
function format(number) 
{ 
if (number < 10) 
{ 
number = "0" + number; 
} 
    return number; 
    } 
// --> 
</script> 
</head> 

<body bgcolor="lightyellow"> 
<h2>Digital Clock</h2> 

<form name="clock" action="#"> 
<p><input type="text" size="8" name="display" value="12:00:00" /></p> 
<p><input type="button" name="display2" value="12:00:00" /></p> 
    </form> 

<script type="text/javascript"> 
setInterval("updateClock()", 1000); // update the clocks every second 
</script> 

<p>More information on the digital clock design can be found 
<a href="time.html">here</a>.</p> 

<p>You can examine the code of the project by clicking on <b>"View" -&gt; 
"Source"</b> buttons in Internet Explorer.</p> 

</body> 
</html> 
+0

很好,不斷的學習,谷歌搜索是很好的,例如「JavaScript的轉換軍事時間「,w3school(w3fool海報噓)。有很多地方需要學習。我會先嚐試谷歌搜索和JavaScript的基礎知識,因爲這是需要較少的物理資源 – alexmac

+0

我應該補充說,在這個網站上,你需要問一些更具體的問題,並似乎已經做了你的搜索答案之前先問但既然你的「新」,我認爲我會幫助,而不是投票 – alexmac

回答

0

行後:

hours = format(hours); 

您應該能夠使用的東西,如:

if (hours > 12) { 
    hours = hours - 12; 
} 
相關問題