Answer by Mohammadreza Askari for how to convert datetime to unix timestamp...
for anyone using gcc, following code is working for me:#define YEAR_OFFSET 1900struct tm* dt = (struct tm*)malloc(sizeof(struct tm));char *strVar = "2022-08-13 23:09:47"; //! "YYYY-MM-DD...
View ArticleAnswer by Alexis Wilke for how to convert datetime to unix timestamp in c?
Linux supports the getdate() function, which I think is more practical than calling strptime() directly. This is because the getdate() function automatically checks many formats for you. It is an...
View ArticleAnswer by tutejszy for how to convert datetime to unix timestamp in c?
Here's a ready snippet when strptime is not available:#include <stddef.h>#include <time.h> #include <stdio.h> time_t string_to_seconds(const char *timestamp_str){ struct tm tm; time_t...
View ArticleAnswer by Sebastião E. Alves Filho for how to convert datetime to unix...
What about sscanf?struct tm tmVar;char *strVar = "YYYY-MM-DD HH:MM:SS";time_t timeVar;if(sscanf(strVar, "%d-%d-%d %d:%d:%d", &tm.tm_year, /* the other fields */)==6) timeVar =...
View ArticleAnswer by merkuro for how to convert datetime to unix timestamp in c?
Here is a wired solution in c/pseudo code I just hacked together. Good luck!char * runner = NULL;char *string_orig = "YYYY-MM-DD HH:MM:SS";time_t time = 0;struct tm tmp;use strstr(string_orig, "-") and...
View ArticleAnswer by Kjetil Joergensen for how to convert datetime to unix timestamp in c?
You could try a combination of strptime and mktimestruct tm tm;time_t epoch;if ( strptime(timestamp, "%Y-%m-%d %H:%M:%S", &tm) != NULL ) epoch = mktime(&tm);else // badness
View ArticleAnswer by Mark Ransom for how to convert datetime to unix timestamp in c?
Convert each part of the date/time into an integer to populate a struct tm, then convert that into a time_t using mktime.
View Articlehow to convert datetime to unix timestamp in c?
the scenario is: I get datetime in format "YYYY-MM-DD HH:MM:SS" with libexif. To minimize the saving cost, I wanna convert the datetime to unix timestamp or alike which only cost 64bit or 32bit. Is...
View Article