Home > Back-end >  24 hours a day and 12 hours of time conversion
24 hours a day and 12 hours of time conversion

Time:10-04

Subject content:
Write a program that asks the user to enter a 24-hour time, then the output display 12 hours of time,

Input format:
In the line with intermediate input: symbol (half Angle of colon) 24-hour time, hours and minutes adopt two digital formats, such as 18 points and 14 points, all said 09:06 said 9, 6 points,

The output format:
In a row in the output corresponding to the time of 12 hours of time, the digital part of the format the same as the input, and then keep up with the space, to keep up with the said morning AM string or said the string of PM in the afternoon, at 5 PM, 6 points such as 05:06 PM said,
Note: in the habit of English, 12 noon is considered to be in the afternoon, so the 24-hour 12:00 is 12 hours of 12:00 PM. The 12 o 'clock at night (24:00) is considered to be the next day, so is 12:00 AM,

Input the sample:
20:09

The output sample:
08:09 PM
Time limit: 500 ms memory limit: 32000 KB

CodePudding user response:


Time transformation & lt;/title> <br/><script LANGUAGE="JavaScript" & gt; <br/>The function timeType () {<br/>If (document) form) showTimeType [0]. Checked) {<br/>//judgment which type choice - 24 hours return true <br/>return true; <br/>} <br/>return false; <br/>} <br/>The function showTheHours (theHour) {<br/>If (timeType () | | (theHour & gt; 0 & amp; & TheHour & lt; 13)) {<br/>//if time within 12 hours <br/>Return (theHour); <br/>} <br/>If (theHour==0) {<br/>//if the time is equal to 0 <br/>Return (12); <br/>} <br/>Return (theHour - 12); <br/>//if the time is more than 12, need to subtract 12 - for 12 hours system <br/>} <br/>The function showZeroFilled (inValue) {<br/>If (inValue & gt; 9) {<br/>//set the number of minutes double-digit show that less than two fill 0 <br/>Return "" + inValue; <br/>} <br/>Return "0" + inValue; <br/>} <br/>The function showAmPm () {<br/>//show that morning or afternoon method <br/>If (timeType ()) {<br/>Return (" "); <br/>} <br/>If (now. GetHours () & lt; 12) {<br/>//date of judgment, according to 12 hours of Chinese tip <br/>Return (" morning "); <br/>} <br/>Return (" afternoon "); <br/>} <br/>The function showTheTime () {<br/>//show the method of time <br/>Now=new Date <br/>//get the current time <br/>Document. The form. The showTime. Value=https://bbs.csdn.net/topics/showTheHours (now. GetHours ()) <br/>+ ":" + showZeroFilled (now. GetMinutes ()) + ":" + <br/>ShowZeroFilled (now. GetSeconds ()) + showAmPm () <br/>SetTimeout (showTheTime "()", 1000) <br/>//update every 1 seconds <br/>} <br/></script> <br/></head> <br/><The BODY onl oad="showTheTime ()" & gt; <br/><Center> <The form name=form> <br/><Input type="text name=showTime size=11 & gt; <p> <br/><Input type=radio name=showTimeType checked> 24 hours & lt; Br> <br/><Input type=radio name=showTimeType> 12 hours & lt; Br> <br/></form> </center> </body> <br/></html> <br/> </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Backend/49753.html" target="_blank" style="color:#999">https//www.codepudding.com/Backend/49753.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Backend/49752.html'>Check all the afternoon I don't know what reason</a></div> <div class="detail-arr-right">Next:<a href='/Backend/49754.html'>Consult a Java problem</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Java+related' target='_blank'>Java related</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>