6 years, 10 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, 10 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)
}

Accepted Answer

Thank you Zoltan Hudak !

posted by PARK JAICHANG 10 Jan 2018

Thank you Anna methew !

posted by PARK JAICHANG 01 Sep 2018

Thank you Zoltan Hudak !

posted by Alonso Felix 16 Apr 2019