Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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

#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
No. Category Subject Author Date Views
315 Develop [java] 스윙(swing)버튼 테스트 ㅋㅋ file hooni 2013.04.23 10310
314 Develop [c] 최대공약수 알고리즘 (유클릿) hooni 2003.04.23 10349
313 Develop 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..) secret hooni 2013.04.23 10366
312 Develop [c] 간단한 채팅(클라이언트/서버) 프로그램 소스 file hooni 2003.04.23 10403
311 Develop [c] 전위 표기법으로 연산 예제.. file hooni 2013.04.23 10404
310 Develop [php] URL/URI 관련 환경변수 hooni 2003.04.23 10422
309 Develop [js] selectbox 선택 후 input 박스에 적용 hooni 2013.04.23 10442
308 Develop [c++] 더블 링크리스트(linked list) 학습용 초간단 단어장 file hooni 2003.04.23 10461
307 Develop [java] Sieve of Eratosthenes (에라토스테네스의 체) hooni 2013.04.23 10464
306 Develop [c] 이진트리(binary tree)의 특성 file hooni 2003.04.23 10555
305 Develop [c++] 마방진 소스코드 file hooni 2013.04.23 10570
304 Develop [js] Closure를 이용해 캡슐화.. hooni 2013.12.16 10570
Board Pagination Prev 1 ... 40 41 42 43 44 45 46 47 48 49 ... 71 Next
/ 71