Skip to content

Instantly share code, notes, and snippets.

@matsumotius
Created July 18, 2011 09:18
Show Gist options
  • Save matsumotius/1088983 to your computer and use it in GitHub Desktop.
Save matsumotius/1088983 to your computer and use it in GitHub Desktop.
time_t sample
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
struct tm *ts;
int year;
char buf[80];
// Get the current time
now = time(NULL);
// Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz"
ts = localtime(&now);
/*
struct tm {
int tm_sec; // 秒
int tm_min; // 分
int tm_hour; // 時
int tm_mday; // 日
int tm_mon; // 月( 1月=0 )
int tm_year; // 西暦年 - 1900
int tm_wday; // 曜日( 日=0 )
int tm_yday; // 日(年を通して)
int tm_isdst; // サマータイムフラグ
};
ex) int hoge = ts->tm_min;
*/
year = 1900 + ts->tm_year;
if(year == 2011){
printf("hello 2011!\n");
}else if(year == 2010){
printf("hello 2010!\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment