Contents

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

시간 날짜, 요일 출력 초간단 예제 코드

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
    time_t  ltime;
    struct tm *today;
    int daysofmonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    char weekstr[][3] = { "일", "월", "화", "수", "목", "금", "토" };
    int year, month, day, month2, th, rmd, adayofweek, OldSec=0;

    while(1){
        time(<ime);
        today = localtime(<ime);

        year = today->tm_year + 1900;
        month = today->tm_mon + 1;
        day = today->tm_mday;

        if (month<=2) {
            rmd = year-1;
            month2 = month+12;
        }
        else {
            rmd = year;
            month2 = month;
        }
        th = rmd/100;
        rmd %= 100;
        adayofweek = (21*th/4 + 5*rmd/4 + 26*(month2+1)/10 + day-1) % 7;

        if ( OldSec != today->tm_sec )
        {
            system("cls");
            printf("%04d. %02d. %02d. (%s) %02d:%02d:%02d KST
",
                // tm_year는 1900을 더해야 서기 연도가 됨
                today->tm_year + 1900,

                // tm_mon은 1월이 0, 2월이 1... 식으로 되어 있음
                today->tm_mon + 1,
                today->tm_mday,
                weekstr[adayofweek],
                today->tm_hour,
                today->tm_min,
                today->tm_sec);
                OldSec = today->tm_sec;
        }
    }
    return 0;
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
841 Develop [ios] App States file hooni 2013.07.22 14537
840 Develop [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 file hooni 2003.04.23 14528
839 System/OS [linux] 셀 스크립트 if, for, case in.. hooni 2003.04.23 14500
838 System/OS [linux] 쉘 스크립트에 대한 설명과 예제.. hooni 2003.04.23 14484
837 Develop [js] 자바스크립트를 동적으로 로딩하기 hooni 2013.04.23 14457
836 Develop [html] 캐쉬된 웹페이지 사용하지 않도록 하는 방법 hooni 2003.04.23 14451
835 System/OS [linux] ipchains 옵션 hooni 2003.04.23 14450
834 System/OS [linux] 기존 환경설정 저장하면서 커널 컴파일.. hooni 2003.04.23 14448
833 System/OS [linux] Xwindow/Xmanager 사용 hooni 2003.04.23 14395
832 System/OS [linux] 간단한 vi편집기 사용 명령 hooni 2003.04.23 14383
831 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 14313
830 Develop [c#] 파일(File) 쓰기 ㅎㅎ hooni 2013.04.23 14296
Board Pagination Prev 1 ... 24 25 26 27 28 29 30 31 32 33 ... 99 Next
/ 99