jquery - Converting isotime to shorttime in javascript -


i have ajax call returns time e.g 16:06:59 want convert 4:06 pm

 var mydate = obj[0].time; 

mydate comes 16:06:59 when try use var date = new date(), gives me todays date .

is there solution realize want ?

thanks

try :

function convert24hoursto12(time) {   var timearray = time.split(':');   var hours = timearray[0];    var minutes = timearray[1];   var ampm = hours >= 12 ? 'pm' : 'am';   hours = hours % 12;   hours = hours ? hours : 12; // hour '0' should '12'   var strtime = hours + ':' + minutes + ' ' + ampm;   return strtime; } 

and call it:

convert24hoursto12(obj[0].time); 

see demo here.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -