I need to convert a string like
"UTC - 9:30 hours"
to minutes.
Something like:
var date = "UTC - 9 : 10 hours";
date = date.replace("UTC",'').replace("hours",'').replace(/\s+/g, '');
var hours = parseInt( date.split(":")[0] );
var minutes = parseInt ( date.split(":")[1] || 0 );
var sign = hours / Math.abs(hours);
var totalMinutes = ( hours * 60 ) + ( sign * minutes );
Can there be an easier way using any regexp? Just curious.
Please be patient…is it too trivial something like this?
oh sorry…you talked about javascript. I posted a c# code..well never mind then.
Anyway the regular expression remains valid.
But to answer your question, no it’s not easier at all as you can see.
p.s.: I handled the sign in a different way just because I didn’t understand your point, and there are lots of
?operators just to allow a looser pattern.