Quantcast
Channel: how to convert datetime to unix timestamp in c? - Stack Overflow
Browsing latest articles
Browse All 8 View Live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

how 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

Browsing latest articles
Browse All 8 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>