I am using WordPress and jQuery Timepicker.
Wordpress gives timezone offset in hours: like +2 or -3.5
jQuery Timepicker takes offset in military hours: +0200 or -0330
I am currently using something like this:
gmt_offset = -4;
hrs_offset = gmt_offset.replace('-', '-0') + "00";
= -0400
But that will break if the offset is not a single negative digit.
gmt_offset = -3.5;
hrs_offset = gmt_offset.replace('-', '-0') + "00";
= -03.500 //No good...
need: -0330
Ack! Can someone help me figure this out?
Here's a nicely compact version:
For example,
militaryGMTOffsetFromNumeric(-3.5)
returns-0330
.Split the offset into 2 parts using
.split(".")
.Give the hour part a "0" if it is less than 10. Then append a negative sign if it is originally negative.
To calculate the minutes part, multiply it by 6.
Here's the final function:
See DEMO.