当前时间的下一秒

简介:
#include <iostream>
#include <cassert>
using namespace std;

class CTime
{
private:
	int year;
	int month;
	int day;
	int hour;
	int minute;
	int second;
public:

	//Judging the input datas whether is validate.
	void validate() const;

	//input datas to the CTime's data members
	void input();

	//count the current time's next second time
	void nextSecond();

	//count the current time's next 100 days' time 
	void next100days();

	//output datas
	void output() const;

	//carry bit for minute if minute is bigger than sixty
	void minuteAdvance();

	//carry bit for second if second is bigger than sixty
	void secondAdvance();

	//carry bit for hour if hour is bigger than twenty-four
	void hourAdvance();

	//carry bit for month if month can be added one 
	bool dayAdvance();

	//carry bit for year if year can be added one
	void monthAdvance();

	//bool isLearYear() const;
};


///////////////////////////////////////
void CTime::secondAdvance()
{
	if (second == 60)
	{
		second = 0;
        minute += 1;
	}	
}
///////////////////////////////////////
void CTime::minuteAdvance()
{
	if (minute == 60)
	{
		hour += 1;
		minute = 0;
	}
}
////////////////////////////////////////
void CTime::hourAdvance()
{
	if (hour == 24)
	{
		day += 1;
		hour = 0;
	}
}
//////////////////////////////////////////
bool CTime::dayAdvance()
{
	switch (month)
	{
	case 1: case 3: case 5: case 7:
	case 8: case 10: case 12:
		if (day > 31)
		{
			day -= 31;
			month += 1;
			return true;
		}
	case 4: case 6: case 9: case 11:
		if (day > 30)
		{
			day -= 30;
			month +=1;
			return true;
		}
	case 2:
		if ((year % 4 == 0 && year % 100) || (year % 400 == 0))
		{
			if (day > 29)
			{
				day -= 29;
				month += 1;
				return true;
			}
		}
		else 
		{
			if (day > 28)
			{
				day -= 28;
				month += 1;
				return true;
			}
		}
	}
	return false;
}
/////////////////////////////////////////
void CTime::monthAdvance()
{
	if (month >= 12)
	{
		month -= 12;
		year += 1;
	}
}
/////////////////////////////////////////
void CTime::output() const
{
	cout << year << "-" << month << "-" << day << ((hour >= 10) ? " " :  " 0") 
		 << hour << ":" << ((minute >= 10) ? "" :  "0")  << minute << ":" 
		 << ((second >= 10) ? "" :  "0")  << second << endl;
}


void CTime::validate() const
{
	assert(year >= 1);
	assert(month >= 1 && month <= 12);
	assert(day >= 1 && day <= 31);
	assert(hour >= 0 && hour <= 23);
	assert(minute >= 0 && minute <= 59);
	assert(second >= 0 && second <= 59);
}

void CTime::input()
{
	cout << "year month day hour minute second:" << endl;
	cin >> year >> month >> day >> hour >> minute >> second;

	validate();
}

void CTime::nextSecond()
{
	second += 1;
	secondAdvance(); //handle second
    minuteAdvance();//
    hourAdvance();
	dayAdvance();
	monthAdvance();
}

void CTime::next100days()
{
	day += 100;
	while (dayAdvance())
	{
		monthAdvance();
	}	
}

int main()
{	
	CTime time;

	time.input();
	cout << endl;
    CTime temp(time);
///////////////////////////////////////////////
	cout << "next second is :" << endl;
	time.nextSecond();
    time.output();
    cout << endl;

	CTime newTime(temp);
///////////////////////////////////////////////
	newTime.next100days();
	cout << "next 100 days is :" << endl;
	newTime.output();
	cout << endl;
	return 0;
}

目录
相关文章
|
5月前
|
SQL 分布式计算 大数据
大数据新视界 --大数据大厂之Hive与大数据融合:构建强大数据仓库实战指南
本文深入介绍 Hive 与大数据融合构建强大数据仓库的实战指南。涵盖 Hive 简介、优势、安装配置、数据处理、性能优化及安全管理等内容,并通过互联网广告和物流行业案例分析,展示其实际应用。具有专业性、可操作性和参考价值。
大数据新视界 --大数据大厂之Hive与大数据融合:构建强大数据仓库实战指南
|
11月前
|
人工智能 自然语言处理 测试技术
苹果一篇论文得罪大模型圈?Transformer不会推理,只是高级模式匹配器!所有LLM都判死刑
苹果公司发布论文《GSM-Symbolic: Understanding the Limitations of Mathematical Reasoning in Large Language Models》,质疑大型语言模型(LLM)在数学推理方面的能力。尽管LLM在GSM8K等测试中表现良好,但在新基准测试GSM-Symbolic中,其准确率随数值变化而显著下降,表明LLM可能依赖于记忆和模式匹配而非真正的数学理解。这一发现引发了AI领域的广泛讨论。
179 5
|
7月前
|
数据采集 弹性计算 运维
阿里云付费模式介绍:节省计划、预留实例券、抢占式实例区别及选择参考
在我们购买阿里云服务器时,可选的付费模式有包年包月、按量付费、节省计划、预留实例券和抢占式5种付费模式,满足长周期低成本以及短周期高弹性的计算要求,一般用户选择最多的是包年包月和按量付费,包年包月购买适合长期稳定的业务,购买周期越长,折扣越高,按量付费购买紧贴业务需求购买资源的付费方式,秒级计费,用多少花多少。本文主要为大家介绍节省计划、预留实例券、抢占式实例三种付费模式,以供参考。
|
7月前
|
人工智能 自然语言处理 数据安全/隐私保护
阿里云中国金融大模型整体市场第一
阿里云以33%的市场份额夺得中国金融大模型整体市场第一
|
人工智能 安全 机器人
新手必看!ChatGPT常见问题总整理,你遇到了几个?
新手必看!ChatGPT常见问题总整理,你遇到了几个?
|
监控 前端开发 JavaScript
React Native开发环境搭建
React Native开发环境搭建
490 0
|
机器学习/深度学习 数据采集 人工智能
ONE-PEACE:探索通往无限模态的通用表征模型
过去几年里,表征模型在自然语言处理、计算机视觉、语音处理等领域取得了巨大的成功。经过大量数据学习的表征模型,不仅可以在各种下游任务上取得良好的效果,还可以作为大规模语言模型(LLM)的基座模型,为LLM提供多模态理解能力。随着多模态技术的发展,尤其CLIP[1]之后大家都意识到一个好的多模态表征模型在很多单模态任务上都会发挥着至关重要的基础模型的作用。学习了大量模态alignment的数据之后的模型逐渐在学会去理解各个模态和模态间蕴含的知识,甚至通过对大量模态的学习促进对其它模态的理解。
22445 7
|
前端开发 JavaScript 容器
保姆级教程 CSS 知识点梳理大全,超详细!!!
保姆级教程 CSS 知识点梳理大全,超详细!!!
|
弹性计算 Oracle Ubuntu
服务器迁移上云步骤、流程及方法
服务器迁移上云步骤、流程及方法,上云是趋势,越来越多企业的IDC服务器选择迁移上云,迁移上云的方式有很多,阿里云提供服务器迁移中心SMC来帮助用户迁移上云。使用SMC服务器迁移中心,将您的源服务器方便快捷地迁移至阿里云,支持的迁移源类型包括IDC服务器、虚拟机、其他云平台的云主机或其他类型的服务器。阿里云SMC服务器迁移中心了解一下,附Linux系统迁移上云和Windows系统迁移上云视频教程:
863 0
|
消息中间件 监控 前端开发
我有 7种 实现web实时消息推送的方案,7种!
我有 7种 实现web实时消息推送的方案,7种!
3876 2
我有 7种 实现web实时消息推送的方案,7种!