Regarding the time format specification.....
the %H for the hours is for the normal 24 hour clock. If you want a 12 hour clock you need to use %I (capital letter India) for the hours in addition to the %p AM/PM indicator. The input routines can get confused if you mix 12 and 24 hour specifications.
Rod.
EDIT: A quick test suggests that if the hours are specified by %H, any AM/PM indicator is ignored. [I withdraw my suggestion that the input routines are confused. If the user wrongly mixes a 12 and a 24 hour format, it chooses to use the 24 hour version, and may well confuse the user!]