跳到正文

休闲·娱乐

时间显示器

kbykby约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年2月6日
收录
2026年3月6日
更新
2026年11月14日
篇幅
约 2 分钟

版本

  1. v1当前

写了一个没什么用的时间显示器

C++
#include<bits/stdc++.h>
#include<windows.h>
#define time0 31536000
#define time1 31622400
#define int long long
using namespace std;
int t,year=1980,month=1,day=1,hour,minute,second,days[2][15]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
bool judge(int y)
{
	return y%4==0&&(y%100!=0||y%400==0);
}
signed main()
{
	while(1)
	{
		system("cls");
		t=time(0)-144000;
		year=1970;
		month=2;
		while(1)
		{
			if(t>=(judge(year)?time1:time0))
			{
				t-=(judge(year++)?time1:time0);
			}
			else break;
		}
		while(1)
		{
			if(t>=days[judge(year)][month]*86400)
			{
				t-=days[judge(year)][month]*86400;
			}
			else break;
		}
		day=t/86400;
		hour=t%86400/3600;
		minute=t%3600/60;
		second=t%60;
		printf("%lld年%lld月%lld日%lld时%lld分%lld秒",year,month,day,hour,minute,second);
		Sleep(10);
	}
	return 0;
}
原文