⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2_5.cpp

📁 一个时间类及一些操作函数
💻 CPP
字号:
// 2_5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream.h"
#include "time.h"

class Time{
public:
	atime();
	void settime(int ,int ,int );
	void printstandard();
private:
	int hour;
	int minute;
	int second;
};
Time::atime()
{
	time_t ltime;
	time(&ltime);
	struct tm *nowtime;
	nowtime=localtime(&ltime);
	hour=nowtime->tm_hour;
	minute=nowtime->tm_min;
	second=nowtime->tm_sec;
}
void Time::settime(int h,int m,int s)
{
	hour=(h>=0&&h<24)?h:0;
	minute=(m>=0&&m<60)?m:0;
	second=(s>=0&&s<60)?s:0;
}
void Time::printstandard()
{
	cout<<((hour==0||hour==12)?12:hour%12)
		<<":"<<(minute<10?"0":"")<<minute
		<<":"<<(second<10?"0":"")<<second
		<<(hour<12?"AM":"PM")
		<<'\n';
}
main()
{
	Time t;
	t.atime();
	t.printstandard();
	t.settime(44,77,122);
    t.printstandard();
	return 0;
}














//_strtime(tmpbuf)
//char tmpbuf[11]
//n=ltime-(365*24*3600)*(ltime/(365*24*3600))-(ltime/(365*24*3600))/4*24*3600;
	//h=n-(n/(24*3600))*24*3600;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -