Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Time in military time?

    How do I get the time in military time? Thanks for any help!
    This is the code that I'm working with and I need it to be in military time:

    <script LANGUAGE="JavaScript">
    <!-- Begin
    Stamp = new Date();
    document.write('<span class="text">' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getYear() + '</span>&nbsp;');
    var Hours;
    var Mins;
    var Secs;
    var Time;
    Hours = Stamp.getHours();
    if (Hours >= 12) {
    Time = " pm";
    }
    else {
    Time = " am";
    }
    if (Hours > 12) {
    Hours -= 12;
    }
    if (Hours == 0) {
    Hours = 12;
    }
    Mins = Stamp.getMinutes();
    if (Mins < 10) {
    Mins = "0" + Mins;
    }
    Secs = Stamp.getSeconds();
    if (Secs < 10) {
    Secs = "0" + Secs;
    }
    document.write('<span class="text">' + Hours + ":" + Mins + ":" + Secs + Time + '</span>');// End -->
    </script>

    Thanks.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    477
    Thanks
    0
    Thanked 51 Times in 50 Posts
    Change this line

    document.write('<span class="text">' + Hours + ":" + Mins + ":" + Secs + Time + '</span>');

    to this

    document.write('<span class="text">' + Stamp.getHours() + ":" + Mins + ":" + Secs + '</span>');

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. Although, I feel like a moron now!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •