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
번호 분류 제목 글쓴이 날짜 조회 수
423 Develop [js] 자바스크립트 이벤트 핸들.. hooni 2003.04.23 9161
422 Develop [c] 문자열 처리 관련 함수들 설명 hooni 2003.04.23 9187
421 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 9200
420 Develop [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 hooni 2003.04.23 9206
419 Develop [c++] Win32API를 이용한 ExitWindowsEx 사용한 예제코드 hooni 2013.04.23 9206
418 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 9212
417 Develop [c] 퀵정렬(quick sort) 예제 소스.. file hooni 2013.04.23 9223
416 Develop [js] 핫키(단축키) 구현방법 hooni 2003.04.23 9224
415 Develop [c] 구구단 최단라인 ㅡㅡ; file hooni 2013.04.23 9226
414 Develop [js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거 file hooni 2013.04.23 9228
413 Develop [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ hooni 2013.04.23 9230
412 Develop [c] GD라이브러리 설치 테스트 소스 file hooni 2013.04.23 9238
Board Pagination Prev 1 ... 31 32 33 34 35 36 37 38 39 40 ... 71 Next
/ 71