C++中error C4996 解决方法

一、实例

#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
#pragma warning(disable:4996)//编译时出现error C4996 解决方法
int main()
{
	// 基于当前系统的当前日期/时间
	time_t now = time(0);

	// 把 now 转换为字符串形式
	char* dt = ctime(&now);

	cout << "本地日期和时间:" << dt << endl;

	// 把 now 转换为 tm 结构
	tm *gmtm = gmtime(&now);
	dt = asctime(gmtm);



	cout << "UTC 日期和时间:" << dt << endl;
	system("pause");
}

二、认识

Coordinated Universal Time(UTC):世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT)比如,中国内地的时间与UTC的时差为东八区,表示为:UTC+8

Calendar Time:日历时间,表示从1970年1月1日0时0点到现在所经过的时间秒数,日历时间是相对时间,无论你在哪一个时区,在同一时刻对同一个标准时间点来说,日历时间都是一样的. 

epoch:英文武译为(新纪元;新时代;时间上的一点),在标准C/C++中是一个整数,它用此时的时间和标准时间点相差的秒数(即日历时间)来表示 

#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
#pragma warning(disable:4996)//编译时出现error C4996 解决方法
int main()
{
	// 基于当前系统的当前日期/时间
	time_t now = time(0);

	cout << "1970 到目前经过秒数:" << now << endl;

	tm *ltm = localtime(&now);

	// 输出 tm 结构的各个组成部分
	cout << "年: " << 1900 + ltm->tm_year << endl;
	cout << "月: " << 1 + ltm->tm_mon << endl;
	cout << "日: " << ltm->tm_mday << endl;
	cout << "时间: " << ltm->tm_hour << ":";
	cout << ltm->tm_min << ":";
	cout << ltm->tm_sec << endl;
	system("pause");
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值