Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. struct tm t;
  2. t.tm_year=4;
  3. t.tm_mon=9;
  4. t.tm_mday=30;
  5. t.tm_hour=0;
  6. t.tm_min=0;
  7. t.tm_sec=0;
  8.  
  9. 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);
  10. //result: 4-9-30 0:0:0, which means 1904 Oct 30 00:00:00
  11.  
  12. mktime(&t);
  13.  
  14. 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);
  15. //result: 4-9-29 23:36:36, which means 1904 Oct 29 23:36:36
  16.  
  17. #include <time.h>
  18. #include <stdio.h>
  19. int main(void) {
  20. struct tm t = {
  21. .tm_year = 4,
  22. .tm_mon = 9,
  23. .tm_mday = 30,
  24. .tm_hour = 0,
  25. .tm_min = 0,
  26. .tm_sec = 0,
  27. .tm_isdst = -1, /* let mktime() figure it out */
  28. };
  29.  
  30. printf("%04d-%02d-%02d %02d:%02d:%02dn",
  31. 1900+t.tm_year, 1+t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
  32. // output: 1904-10-30 00:00:00
  33.  
  34. mktime(&t);
  35.  
  36. printf("%04d-%02d-%02d %02d:%02d:%02dn",
  37. 1900+t.tm_year, 1+t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
  38. // output: 1904-10-29 23:36:42
  39. }
  40.  
  41. $ ./c
  42. 1904-10-30 00:00:00
  43. 1904-10-30 00:00:00
  44. $ TZ=Asia/Hong_Kong ./c
  45. 1904-10-30 00:00:00
  46. 1904-10-29 23:36:42
  47. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement