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
번호 분류 제목 글쓴이 날짜 조회 수
313 Develop [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ file hooni 2013.04.23 8881
312 Develop [c++] 바탕화면 테두리에 자석처럼 붙는 스냅효과.. file hooni 2013.04.23 8907
311 Develop [js] 밀리터리 프로그램(전역일 계산) 7 file hooni 2013.04.23 8913
310 Develop [js] 객체 머지.. hooni 2013.12.17 8966
309 Develop [c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현 file hooni 2013.04.23 8970
308 Develop [c] 간단한 채팅(클라이언트/서버) 프로그램 소스 file hooni 2003.04.23 9070
307 Develop [c] OpenGL 직사각형(2D) 크기 확대/축소 hooni 2003.04.23 9070
306 Develop [c] 디피-헬만 키교환(Diffie–Hellman key exchange) 샘플 코드.. ㅋㄷ file hooni 2013.04.23 9112
305 Develop [c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ file hooni 2013.04.23 9123
304 Develop 다운 받아서 테스트 해볼것.. hooni 2013.04.23 9144
303 Develop [c] 하노이탑 - 재귀함수 hooni 2003.04.23 9155
302 Develop [php] URL/URI 관련 환경변수 hooni 2003.04.23 9163
Board Pagination Prev 1 ... 40 41 42 43 44 45 46 47 48 49 ... 71 Next
/ 71