Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct tm t;
- t.tm_year=4;
- t.tm_mon=9;
- t.tm_mday=30;
- t.tm_hour=0;
- t.tm_min=0;
- t.tm_sec=0;
- printf("%d-%d-%d %d:%d:%dn", t.tm_year, t.tm_mon, t.tm_day, t.tm_hour, t.tm_min, t.tm_sec);
- //result: 4-9-30 0:0:0, which means 1904 Oct 30 00:00:00
- mktime(&t);
- printf("%d-%d-%d %d:%d:%dn", t.tm_year, t.tm_mon, t.tm_day, t.tm_hour, t.tm_min, t.tm_sec);
- //result: 4-9-29 23:36:36, which means 1904 Oct 29 23:36:36
- #include <time.h>
- #include <stdio.h>
- int main(void) {
- struct tm t = {
- .tm_year = 4,
- .tm_mon = 9,
- .tm_mday = 30,
- .tm_hour = 0,
- .tm_min = 0,
- .tm_sec = 0,
- .tm_isdst = -1, /* let mktime() figure it out */
- };
- printf("%04d-%02d-%02d %02d:%02d:%02dn",
- 1900+t.tm_year, 1+t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
- // output: 1904-10-30 00:00:00
- mktime(&t);
- printf("%04d-%02d-%02d %02d:%02d:%02dn",
- 1900+t.tm_year, 1+t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
- // output: 1904-10-29 23:36:42
- }
- $ ./c
- 1904-10-30 00:00:00
- 1904-10-30 00:00:00
- $ TZ=Asia/Hong_Kong ./c
- 1904-10-30 00:00:00
- 1904-10-29 23:36:42
- $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement