Last active
April 29, 2021 15:51
-
-
Save wpyoga/0143e51bef071cd95e39defc7f34a47f to your computer and use it in GitHub Desktop.
convert time string to struct tm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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