trentrichardson/jQuery-Timepicker-Addon — pull request #492 by rocksolidwebdesign (2012-10-24 06:57:32+00:00)
Title: 12 hour format, force alt field to always be UTC

Here is one fix and one feature

The fix addresses issue(s) #459 and #479

to use the fix simply use a capital "H" instead of a lower case "h" in your time format specifier to force usage of 12 hour time format, "HH" with leading zero and "H" without, for example. The `ampm` option now only affects the process of time picking and not the resulting output. If you

$("foo").datetimepicker({
"timeFormat": "H:mm",
"altTimeFormat": "HH:mm:ss"
});

and of course, you can still use lower case "h" to get a nice display format on the frontend and a more easily parsable format for the backend

$("foo").datetimepicker({
"timeFormat": "H:mm",
"altTimeFormat": "hh:mm:ss"
});

The feature is part of a related request wherein it's much easier and more standard (I find) to store dates in UTC format to aid in dealing with timezone differences and I prefer to have my dates converted to UTC before they get send to the server, hence this feature:

The feature also entails being able to properly calculate the UTC time appropriately given the selected timezone.

I added an option `altForceUtc` and it defaults to `false` - to use it, simply set it to `true`. The `altForceUtc` feature currently only takes effect when `altFieldTimeOnly == false` as it doesn't seem to make much sense in any other context.

$("foo").datetimepicker({
"altFieldTimeOnly": false,
"altForceUtc": true
});

and combining all of the above to create a datetime picker where the user sees and enters time in 12 hour format in any time zone, but the backend (presumably the alt field is a hidden input in this case) receives UTC 24hr format

$("foo").datetimepicker({
"timeFormat": "H:mm",
"altTimeFormat": "hh:mm:ssZz",
"altFieldTimeOnly": false,
"altForceUtc": true
});

you can see a working demo here: http://jsfiddle.net/SyNCp/

notice that the UTC date (not just the time) may diverge from the displayed time, that is the altField may actually report one day ahead or behind the displayed time - this is the intended and desired behavior

cheers