Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery convert hmm format to hour

Tags:

jquery

time

My weather forecast program use a service. This service give me time for each day. But this time format is 'hmm'. I don't know this format. So ı ask how can ı convert this ??

    $('.table tbody tr:eq(' + j + ') td:eq(0)').text(data.weather[gunSayisi].hourly[j].time);

this is my code ı got json data ı want to convert this time format to hour Here is my data : http://www.jsoneditoronline.org/?id=0e98f3e93aeb98d337bb8b0df25928ed

like image 478
Ertuğrul Karababa Avatar asked Nov 28 '25 13:11

Ertuğrul Karababa


1 Answers

hmm means hour minute minute, so, to reach the number of hours as an integer, you need to divide and round, like this:

var hours = Math.floor(value / 100);

If you want to get the number as float, then you need to gather the number of hours, the number of minutes and convert the number of minutes into decimals:

var h = parseInt(value.substring(0, value.length - 2));
var m = parseInt(value.substring(value.length - 2));
var hours = h + (m / 60);

Or in short:

var hours = parseInt(value.substring(0, value.length - 2)) + (parseInt(value.substring(value.length - 2)) / 60);
like image 191
Lajos Arpad Avatar answered Nov 30 '25 04:11

Lajos Arpad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!