Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 11 months ago.
How can I convert input Date Time to Unix Time(Epoch Time) ?
Hello
How can I convert to input from Date Time to Unix Time(Epoch Time) ?
for example, I input Date and time like 2018 01 09 12:12:12
need Output Value : UnixTime
1 Answer
6 years, 11 months ago.
Hello Park,
You can try the following function:
time_t asUnixTime(int year, int mon, int mday, int hour, int min, int sec) { struct tm t; t.tm_year = year - 1900; t.tm_mon = mon - 1; // convert to 0 based month t.tm_mday = mday; t.tm_hour = hour; t.tm_min = min; t.tm_sec = sec; t.tm_isdst = -1; // Is Daylight saving time on? 1 = yes, 0 = no, -1 = unknown return mktime(&t); // returns seconds elapsed since January 1, 1970 (begin of the Epoch) }