Skip to content

Instantly share code, notes, and snippets.

@wpyoga
Last active April 29, 2021 15:51
Show Gist options
  • Save wpyoga/0143e51bef071cd95e39defc7f34a47f to your computer and use it in GitHub Desktop.
Save wpyoga/0143e51bef071cd95e39defc7f34a47f to your computer and use it in GitHub Desktop.
convert time string to struct tm
#define _XOPEN_SOURCE
#include <time.h>
#include <stdio.h>
// Simple-task-30036777
int main() {
char buf[] = "2021-04-28T21:29:10.279Z";
int len;
struct tm tmbuf;
char *c = NULL;
c = strptime(buf, "%Y-%m-%dT%H:%M:%S", &tmbuf);
printf("Y M D: %d %d %d\nH M S: %d %d %d\n", 1900+tmbuf.tm_year, 1+tmbuf.tm_mon, tmbuf.tm_mday, tmbuf.tm_hour, tmbuf.tm_min, tmbuf.tm_sec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment