MkTime gibt einen falschen Wert zurück [geschlossen]Linux

Linux verstehen
Anonymous
 MkTime gibt einen falschen Wert zurück [geschlossen]

Post by Anonymous »

Ich habe den folgenden Quellcode: < /p>

Code: Select all

time_t test(void)
{
int year = 2025, month = 5, day = 11, hour = 16, minute = 32, second = 9;
struct tm t = {0};

t.tm_year = year - 1900;
t.tm_mon = month - 1;
t.tm_mday = day;
t.tm_hour = hour;
t.tm_min = minute;
t.tm_sec = second;
t.tm_isdst = -1;

logprintf("Before mktime: tm_year=%d, tm_mon=%d, tm_mday=%d, tm_hour=%d, tm_min=%d, tm_sec=%d, tm_isdst=%d\n",
t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, t.tm_isdst);

logprintf("%d: expiration time of cert in YY-MM-DD format: %d-%d-%d %d:%d:%02d\n", __LINE__, year, month, day, hour, minute, second);

time_t res = mktime(&t);
logprintf("%d: expiration time of cert in epoch time  %ld\n", __LINE__, res);
return res;  // Convert to epoch time (local timezone)

}
int main(void)
{
test();
return 0;
}
< /code>
Dies gibt die folgende Ausgabe zurück < /p>
# ./test
Before mktime: tm_year=125, tm_mon=4, tm_mday=11, tm_hour=16, tm_min=32, tm_sec=9, tm_isdst=-1
4986: expiration time of cert in YY-MM-DD format: 2025-5-11 16:32:09
4989: expiration time of cert in epoch time  0
Warum mkTime () retektiert 0. Was fehlt mir?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post