Skip to content

Instantly share code, notes, and snippets.

@mather
Created February 12, 2013 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mather/4761475 to your computer and use it in GitHub Desktop.
Save mather/4761475 to your computer and use it in GitHub Desktop.
tzsetで何が変わるのか
#include <stdio.h>
#include <time.h>
void print_time(const time_t t)
{
char buf[128];
size_t str_size = 0;
str_size = strftime(buf, 127, "%Y/%m/%d %H:%M:%S", localtime(&t));
buf[str_size] = 0;
printf("%s\n",buf);
}
int main(int argc, char *argv[])
{
int i;
printf("== Before tzset() ==\n");
for(i=0;i<2;i++) {
printf("tzname[%d]: %s\n",i,tzname[i]);
}
printf("timezone: %ld (h)\n",timezone/(60*60));
print_time(time(NULL));
tzset(); /* call tzset() */
printf("== After tzset() ==\n");
for(i=0;i<2;i++) {
printf("tzname[%d]: %s\n",i,tzname[i]);
}
printf("timezone: %ld (h)\n",timezone/(60*60));
print_time(time(NULL));
return 0;
}
/*
time(NULL)の値が変わるわけではないことに注意。
== Before tzset() ==
tzname[0]: WILDABBR
tzname[1]: WILDABBR
timezone: 0 (h)
2013/02/12 19:34:10
== After tzset() ==
tzname[0]: JST
tzname[1]: JDT
timezone: -9 (h)
2013/02/12 19:34:10
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment