Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Created December 13, 2012 14:48
Show Gist options
  • Save cofearabi/4276825 to your computer and use it in GitHub Desktop.
Save cofearabi/4276825 to your computer and use it in GitHub Desktop.
(c language) display the time. if between 11:32~12:28 return 1 else return 0
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t timer;
struct tm *t_st;
/* 現在時刻の取得 */
time(&timer);
/* 現在時刻を文字列に変換して表示 */
printf("現在時刻: %s\n", ctime(&timer));
/* 現在時刻を構造体に変換 */
t_st = localtime(&timer);
printf("月: %d\n",t_st->tm_mon+1); /* 月は+1 */
printf("日: %d\n",t_st->tm_mday);
printf("時: %d\n",t_st->tm_hour);
printf("分: %d\n",t_st->tm_min);
printf("秒: %d\n",t_st->tm_sec);
if( t_st->tm_hour == 11 && t_st->tm_min > 32 ) return 1;
if( t_st->tm_hour == 12 && t_st->tm_min < 28 ) return 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment