www.webdeveloper.com
Results 1 to 2 of 2

Thread: army time

  1. #1
    Join Date
    Jul 2010
    Posts
    14

    army time

    How do I get this into regular time instead of army time?

    Code:
        <p id="time">
    	<script type="text/javascript">
    		var	now = new Date();
    		var	hours = now.getHours();
    		var	minutes = now.getMinutes();
    		document.write ("Page last refreshed at " + hours + ":" + minutes)
    	</script>
    
        </p>

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    Code:
        <p id="time">
    	<script type="text/javascript">
                    function pad(n) {
                        return (n < 10) ? '0' + n : n;
                    }
    		var	now = new Date();
    		var	hours = now.getHours();
    		var	minutes = now.getMinutes();
                    var am_pm = (hours < 12) ? 'a.m.' : 'p.m.';
                    if (hours > 12) {
                        hours -= 12;
                    } else if (hours === 0) {
                        hours = 12;
                    }
    		document.write ("Page last refreshed at " + hours + ":" + pad(minutes) + am_pm)
    	</script>
    
        </p>
    Last edited by astupidname; 07-23-2010 at 03:02 AM. Reason: forgot about the zero hour, added that and zero padding for minutes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles