Answer the question
In order to leave comments, you need to log in
Changing clocks in Solaris and localtime/mktime/asctime, what am I doing wrong?
Colleagues, there is such a code in C:
#include <time.h>
#include <stdio.h>
int main() {
time_t t;
struct tm tm1;
tzset();
time(&t);
localtime_r(&t, &tm1);
printf("\n now:\t\t\t(%d) %s", t, asctime(&tm1));
tm1.tm_mday = 26;
tm1.tm_sec = 59;
tm1.tm_min = 59;
tm1.tm_hour = 1;
tm1.tm_mon = 9;
t = mktime(&tm1);
printf(" tm_hour = 1:\t\t(%d) %s", t, asctime(&tm1));
tm1.tm_mday = 26;
tm1.tm_sec = 59;
tm1.tm_min = 59;
tm1.tm_hour = 0;
tm1.tm_mon = 9;
t = mktime(&tm1);
printf(" tm_hour = 0:\t\t(%d) %s", t, asctime(&tm1));
t += 3602;
localtime_r(&t, &tm1);
printf(" 3602 seconds later:\t(%d) %s", t, asctime(&tm1));
t -= 3604;
localtime_r(&t, &tm1);
printf(" 3604 seconds before:\t(%d) %s\n", t, asctime(&tm1));
}
Answer the question
In order to leave comments, you need to log in
More hell:
#include <time.h>
#include <stdio.h>
int main() {
time_t t;
struct tm tm1;
tzset();
time(&t);
localtime_r(&t, &tm1);
tm1.tm_mday = 27;
tm1.tm_sec = 59;
tm1.tm_min = 59;
tm1.tm_hour = 0;
tm1.tm_mon = 9;
t = mktime(&tm1);
printf(" tm_hour = %d:\t\t(%d) %s", tm1.tm_hour, t, asctime(&tm1));
tm1.tm_mday = 26;
tm1.tm_sec = 59;
tm1.tm_min = 59;
tm1.tm_hour = 0;
tm1.tm_mon = 9;
t = mktime(&tm1);
printf(" tm_hour = %d:\t\t(%d) %s", tm1.tm_hour, t, asctime(&tm1));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question