Either use %r
or %I:%M:%S %p
(note it's I
not H
).
From man strptime
(emphasis by me):
%r
The 12-hour clock time (using the locale's AM or PM). In the POSIX locale equivalent to %I:%M:%S %p.
The lesson learned here: RTFM!
Test program:
#define _XOPEN_SOURCE
#include <time.h>
const char d[] = "Apr 3, 2014 4:44:39 PM";
int main(void)
{
struct tm t = { 0 };
strptime(d, "%b %d, %Y %I:%M:%S %p", &t);
}
Checking the result:
$gdb ./main
[...]
b 12
r
Breakpoint 1, main () at main.c:12
12 }
(gdb) p t
$2 = {tm_sec = 39, tm_min = 44, tm_hour = 16, tm_mday = 3, tm_mon = 3, tm_year = 114, tm_wday = 4, tm_yday = 92, tm_isdst = 0, __tm_gmtoff = 0, __tm_zone = 0x0}
(gdb)