'요일계산'에 해당되는 글 1건

관련글: http://joinc.co.kr/modules.php?op=modload&name=Forum&file=viewtopic&topic=31448&forum=1

문제점: 한주의 시작을 일요일로 정의할것인지 월요일로 정의할것인지 필요.

코드:
#include <stdio.h>
#include <string.h>
#include <time.h>

int (week_of_year)(time_t s_time_t)
{
 struct tm *s_tm;
 s_tm = localtime((time_t *)(&s_time_t));
 return(((s_tm->tm_yday + (6 - s_tm->tm_wday)) / 7) + 1);
}

int (main)(void)
{
 time_t s_time_t;

 s_time_t = time(NULL);

 (void)fprintf(stdout, "current time = %snweek of year = %dn",
  ctime((time_t *)(&s_time_t)),
  week_of_year(s_time_t));

 return(0);
}

/* End of source */
크리에이티브 커먼즈 라이센스
Creative Commons License
Posted by minzkn

트랙백 주소 :: http://blog.minzkn.com/trackback/155

댓글을 달아 주세요