[Solved] how to convert “05:30” String value into integer using javascript


Let’s say the time zone offsets are valid, they are in hours and minutes always separated by a colon (‘:’) and preceded by a ‘+’ or ‘-‘.

So

var utcOffset = "+05:30";
var a = uctOffset.split(':');
var hour = +a[0];
var minute = +a[1];

What you do with the hour and minute values is up to you – but if the hour is negative, the minutes might need to be made negative too. I suggest you use isNaN to check the minute is valid if it may be absent:

if( isNaN( minute)
   minute = 0;

solved how to convert “05:30” String value into integer using javascript