(时间范围: 1970 ~ 2105 年)
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
int main ()
{
int year, month, n;
printf ("年: ");
scanf ("%d", &year);
printf ("月: ");
scanf ("%d", &month);
time_t t, t1;
struct tm *mkt = new tm, *gmt;
t = time(NULL);
mkt = gmtime(&t);
mkt->tm_mday = 1;
mkt->tm_mon = month - 1;
mkt->tm_year = year - 1900;
t1 = mktime(mkt);
n = mkt->tm_wday;
gmt = mkt;
COORD p;
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
while (true)
{
system ("cls");
p.X = 0;
p.Y = 0;
SetConsoleCursorPosition (out, p);
t = time(NULL);
gmt = gmtime(&t);
printf ("%d 年 %d 月 %02d:%02d:%02d\n\n日 一 二 三 四 五 六", year, month, gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
t = t1;
gmtime(&t);
do
{
p.X = gmt->tm_wday * 3;
p.Y = (gmt->tm_mday + n - 1) / 7 + 3;
SetConsoleCursorPosition (out, p);
printf ("%d ", gmt->tm_mday);
t += 86400;
gmtime(&t);
}
while (gmt->tm_mday > 1);
Sleep (1000);
}
return 0;
}