changing gethours in javascript to 1-12 -
i'm trying use gethours() method in javascript keeps returning military time. can please me out fixing displays clock time? (1-12). thank much!
// reroute conf.js script var chat = $( '.chat-output' ), message = function ( message, userid ) { var dt = new date(), time = dt.gethours() + ":" + dt.getminutes(); // + ":" + dt.getseconds(); return $( '<div class="chat-message color-' + users[userid] + '">' + '<div class="chat-id color-' + users[userid] + '"></div>' + '<div class="chat-user-message">' + message + '</div>' + '<div class="chat-time">' + time + '</div>' + '</div>' ); }, addtext = function ( text ) { // log.innerhtml += text; // log.scrolltop = log.scrollheight; console.log( text ); }, addremotetext = function ( userid, text ) { // addtext( '[' + userid + ']: ' + text+'<br>' ); chat.append( message( text, userid ) ); chat.scrolltop( chat.get( 0 ).scrollheight ); };
function ampm(date){ var dt= date || new date, h= dt.gethours(), m= dt.getminutes(), s= dt.getseconds(), ampm; if(h>12){ h-= 12; ampm= (h%12)? ' pm': ' am'; } else ampm= (h%12)? ' am': ' pm'; m= m<10? '0'+m: m; s= s<10? '0'+s: s; return [h, m, s].join(':')+ampm; } ampm()
/* returned value: (string) 11:52:55 pm */
Comments
Post a Comment