C++_当前时间 | 计时器

//将当前时间折算为秒级,再通过函数转换成时分秒
#include<iostream>  
#include<iomanip>
#include<ctime>  
using namespace std;
int main()
{
	time_t now_time;
	now_time = time(NULL);    // 获取当前时间
	cout << now_time << endl;

	struct tm time;
	localtime_s(&time, &now_time);    // 时间转换函数

	cout << setw(2) << setfill('0') << time.tm_hour << ":";    // 设置字符宽度与填充
	cout << setw(2) << setfill('0') << time.tm_min << ":";
	cout << setw(2) << setfill('0') << time.tm_sec;

	cin.get();
	return 0;
}

struct tm {
        int tm_sec;     /* 秒 - [0,59] */
        int tm_min;     /* 分 - [0,59] */
        int tm_hour;    /* 时 - [0,23] */
        int tm_mday;    /* 日 - [1,31] */
        int tm_mon;     /* 月 - [0,11] */
        int tm_year;    /* 年 1900 */
        int tm_wday;    /* 星期 - [0,6] */
        int tm_yday;    /* 天 1 - [0,365] */
        int tm_isdst;   /* 夏令时 - [1,-1] */
        };

 

计时器:

int main()
{
	system("color 6A");

	clock_t start, finish;
	double totaltime;
	start = clock();
	Sleep(1000);
	finish = clock();
	totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
	cout << "\n排序运行时间为:" << totaltime << "秒!" << endl;

	system("pause");
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值