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;
}


?

  1. [c] vc++ 에서 clrscr(), gotoxy() 함수 사용하기..

    Date2013.04.23 CategoryDevelop Byhooni Views14254
    Read More
  2. [c] 가변인자 함수(printf와 같은..)

    Date2013.04.23 CategoryDevelop Byhooni Views7179
    Read More
  3. [c] 가위 바위 보 서버, 클라이언트 소스코드

    Date2003.04.23 CategoryDevelop Byhooni Views8180
    Read More
  4. [c] 간단한 링크드 리스트(linked list) 자료형 예제..

    Date2003.04.23 CategoryDevelop Byhooni Views9841
    Read More
  5. [c] 간단한 소켓 프로그래밍 샘플

    Date2013.04.23 CategoryDevelop Byhooni Views8164
    Read More
  6. [c] 간단한 순위 루틴.. (정보처리기사)

    Date2003.04.23 CategoryDevelop Byhooni Views6874
    Read More
  7. [c] 간단한 순위 루틴.. (질문에 대한 답변)

    Date2003.04.23 CategoryDevelop Byhooni Views7469
    Read More
  8. [c] 간단한 자료구조(stack, queue, linked list) 구현 소스

    Date2003.04.23 CategoryDevelop Byhooni Views10120
    Read More
  9. [c] 간단한 점 이동 샘플 소스코드

    Date2013.04.23 CategoryDevelop Byhooni Views6546
    Read More
  10. [c] 간단한 채팅(클라이언트/서버) 프로그램 소스

    Date2003.04.23 CategoryDevelop Byhooni Views9070
    Read More
  11. [c] 거리와 각도를 입력받아서 좌표로 변환

    Date2013.04.23 CategoryDevelop Byhooni Views10818
    Read More
  12. [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스..

    Date2013.04.23 CategoryDevelop Byhooni Views7370
    Read More
Board Pagination Prev 1 ... 17 18 19 20 21 22 23 24 25 26 ... 98 Next
/ 98