Is one aware of a date parsing function for c. I am looking for something like:
time = parse_time("9/10/2009");
printf("%d\n", time->date);
time2 = parse_time("Monday September 10th 2009")
time2 = parse_time("Monday September 10th 2009 12:30 AM")
Thank you
There are two fairly common approaches in C:
Use strptime() with an array of supported formats you accept.
Bang head against table a lot, and then either give up or use another language which has a usable library already (like perl or python).
If the format is consistent you can use scanf
family functions
#include<stdio.h>
int main()
{
char *data = "Tue, 13 Dec 2011 16:08:21 GMT";
int h, m, s, d, Y;
char M[4];
sscanf(data, "%*[a-zA-Z,] %d %s %d %d:%d%:%d", &d, M, &Y, &h, &m, &s);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With