function secondsToTime(secs)
{
var hours = Math.floor(secs / (60 * 60));
var divisor_for_minutes = secs % (60 * 60);
var minutes = Math.floor(divisor_for_minutes / 60);
var divisor_for_seconds = divisor_for_minutes % 60;
var seconds = Math.ceil(divisor_for_seconds);
if(hours >= 12)
{
var m= 'pm' ;
}
else
{
var m='am'
}
if(hours-12 >0)
{
var hrs = hours-12;
}
else if(hours-12 <0)
{
var hrs = hours;
}
var obj = {
"h": hrs,
"m": minutes,
"s": seconds,
"a":m
};
return obj;
}
var d = new Date();
var n = d.getHours();
var hms = d.getHours()+':'+d.getMinutes()+':'+d.getSeconds(); // your input string
var a = hms.split(':'); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
console.log(seconds);
console.log(secondsToTime(seconds))
https://jsfiddle.net/jithinksoft/9x6z4sdt/