I've been playing with jquery and I've run myself into a time problem. I've got 3 time input select boxes, one for hours, one for minutes, and one for the Meridian. I need to convert this time into a 24 hour string format and then stick it into a hidden input.
var time = "";
time += $("#EventCloseTimeHour option:selected").text();
time += ":" + $("#EventCloseTimeMin option:selected").text() + ":00";
time += " " + $("#EventCloseTimeMeridian option:selected").text();
$("#ConditionValue").val(time);
This gives me "1:30:00 pm" where I need "13:30:00". Any quick javascript time tips?
The key to this solution is using the conditional operator "a?b:c" which translates to "if a then b else c"
You should look into the native JavaScript Date Object methods.
I got it with a few people's answers.
Just to add a plain JS answer, the following will format the time based on the length of the initial string. If h:mm returns HH:mm, if h:mm:ss returns HH:mm:ss.
If HH:mm:ss is always required, it's simple to add default seconds of ":00" if not present in initial string.
Example of tj111 suggestion:
Or you can use: