Javascript 24hr-time issue

Discussion in 'JavaScript' started by SuPrAiCeR69, May 6, 2009.

  1. #1
    I looked around for a 24hr JS time script and found the following from http://www.crays.com/jsc/jsC4Udate.htm:

    Time in 24-hr format

    <SCRIPT Language="JavaScript">
    <!-- hide from old browsers
      var curDateTime = new Date()
      var curHour = curDateTime.getHours()
      var curMin = curDateTime.getMinutes()
      var curSec = curDateTime.getSeconds()
      var curTime = 
        ((curHour < 10) ? "0" : "") + curHour + ":" 
        + ((curMin < 10) ? "0" : "") + curMin + ":" 
        + ((curSec < 10) ? "0" : "") + curSec 
      document.write(curTime)
    //-->
    </SCRIPT>
    Code (markup):
    After testing it, I realised at 12pm the time goes to "00:00:00" instead of staying at 12. At 12am the time goes to "00:00:00" which is fine. How can I fix this or is there a better written script around?
     
    SuPrAiCeR69, May 6, 2009 IP
  2. SuPrAiCeR69

    SuPrAiCeR69 Peon

    Messages:
    216
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Another questions is how to code the following;

    If the time is between 7pm and 7am
    do this​
    else
    If the time is between 7am and 7pm
    do this​
     
    SuPrAiCeR69, May 6, 2009 IP
  3. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hi SuPrAiCeR69,
    I hope this will work:
    Martin
     
    Martin K, May 14, 2009 IP