Convert date zu unix-timestamp in c++

Als einige websites, konvertieren Sie diese unix-Zeitstempel sagen, den Stempel der

2013/05/07 05:01:00 (yyyy/mm/dd, hh:mm:ss) is 1367902860.

Die Art, wie ich es in C++, der Stempel unterscheidet sich von dem Datum.
Hier ist der code:

time_t rawtime;
struct tm * timeinfo;

int year=2013, month=5, day=7, hour = 5, min = 1, sec = 0;

/* get current timeinfo: */
time ( &rawtime ); //or: rawtime = time(0);
/* convert to struct: */
timeinfo = localtime ( &rawtime ); 

/* now modify the timeinfo to the given date: */
timeinfo->tm_year   = year - 1900;
timeinfo->tm_mon    = month - 1;    //months since January - [0,11]
timeinfo->tm_mday   = day;          //day of the month - [1,31] 
timeinfo->tm_hour   = hour;         //hours since midnight - [0,23]
timeinfo->tm_min    = min;          //minutes after the hour - [0,59]
timeinfo->tm_sec    = sec;          //seconds after the minute - [0,59]

/* call mktime: create unix time stamp from timeinfo struct */
date = mktime ( timeinfo );

printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", date);

Den daraus resultierenden Zeit-Stempel wird

1367899260, but not 1367902860.

Was ist hier das problem? Auch wenn ich auf h-1 oder h+1, nicht entspricht. EDIT: Na ja, wenn ich um 1 Stunde, dann funktioniert es. auch vorher Hinzugefügt 1 bis Minuten.

InformationsquelleAutor user2366975 | 2014-02-10

Schreibe einen Kommentar