-
2022-05-21 20:36:15
利用C++实现以下功能:
1.获取当前时间
2.可设置时间
3.可执行天数加一的操作
代码如下:
#include <iostream> #include<ctime> #include<cstdio> #include<time.h> using namespace std; class Date { public: void _gettime(); //获取当前时间 void _entrance(int Year, int month, int day); //输入函数 void _exit(); //输出函数 void change(); //执行加一天操作 void clear(); //清屏 private: int year; int month; int day; }; void Date::_gettime() { struct tm p; //新时间结构体 const time_t t = time(NULL); //获取系统时间,需传入time_t类型的变量地址 localtime_s(&p, &t); printf("当前时间为:%d/%d/%d", p.tm_mday, p.tm_mon + 1, p.tm_year + 1900); } void Date::_entrance(int Day, int Month, int Year) { year = Year; month = Month; day = Day; } void Date::_exit() { printf("%d/%d/%d", day, month, year); } void Date::change() //加一天 { int a[13] = { 29,31,28,31,30,31,30,31,31,30,31,30,31 }; if ((year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) && month == 2 && day == 28) //闰年二月份有29天 day++; else if (a[month] <= day && month != 12) { //满天数进一 month++; day = 1; } else if (a[month] <= day && month == 12) { //满月数年进一 month = 1; day = 1; } else { day++; } } void Date::clear() { system("cls"); } int main() { Date date; int a = 0, b = 0, c = 0; date._gettime(); cout << endl; cout << "输入当前时间(格式-日月年):"; cin >> a >> b >> c; date._entrance(a, b, c); date._exit(); cout << endl; cout << "若执行加一天操作请按1" << endl; int d = 0; cin >> d; if (d == 1) { date.change(); date._exit(); } }
更多相关内容 -
C++获取当前时间精确到毫秒Ms
2021-03-22 17:03:37C++获取当前时间精确到毫秒Ms -
C++获取当前系统时间的方法总结
2021-01-01 01:39:23本文实例讲述了C++获取当前系统时间的方法。分享给大家供大家参考。具体如下: 方案— 优点:仅使用C标准库;缺点:只能精确到秒级 #include #include int main( void ) { time_t t = time(0); char tmp[64]; ... -
C++获取当前时间
2022-01-13 14:42:00运行效果如下: 代码如下: #define _CRT_SECURE_NO_WARNINGS ... } struct tm*指针里面有所有关于时间的变量。其成员定义如下: 使用std::stringstream是因为可以任意添加数字进去,如果用std::string添加数字很麻烦。运行效果如下:
代码如下:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <ctime> int main() { time_t t = time(nullptr); struct tm* now = localtime(&t); std::stringstream time; time << now->tm_year + 1900 << "年"; time << now->tm_mon + 1 << "月"; time << now->tm_mday << "日 "; time << now->tm_hour << ":"; time << now->tm_min << ":"; time << now->tm_sec; std::cout << time.str(); getchar(); return 0; }
struct tm*指针里面有所有关于时间的变量。其成员定义如下:
使用std::stringstream是因为可以任意添加数字进去,如果用std::string添加数字很麻烦。
-
c++获取当前时间(附实例源码)
2022-04-24 17:19:15哈喽 c++作为一个平时玩耍的好伙伴, 也是有很多好玩或者实用的功能, 今天来教一下大家如何用c++获取当前时间 嘿嘿 这个其实也很简单哈喽
今天一打开洛谷,发现
啊这
算了,编程放松一下(放松?)
c++作为一个平时玩耍的好伙伴,
也是有很多好玩或者实用的功能,
今天来教一下大家如何用c++获取当前时间
嘿嘿
这个其实也很简单
time.h头文件详解
定义
- 世界标准时间:格林尼治时间(Greenwich Mean Time,GMT),中国内地时间为UTC+8,美国是UTC-5
- 日历时间:从一个标准时间点到此时的时间经过的秒数,“相对时间”
- 时间点:长整型,当前时间和标准时间相差的秒数。
- 时钟计时单元:C/C++基本计时单位
说明
这个可以自己看time.h的代码可以找到
我已经整理出来了
<time.h> clock_t clock(void);//从进程开始到调用clock之间的CPU时钟计时单元 CLOCKS_PER_SEC//CPU时钟计时单元,1秒钟会有多少个时钟计时单元 #define CLOCKS_PER_SEC ((clock_t)1000) time_t time(time_t* timer);//返回从1970年1月1日0时0分0秒到现在的秒数 struct tm* gmtime(const time_t *timer);//将日历时间转化为世界标准时间(格林尼治时间) struct tm* localtime(const time_t *timer);//将日历时间转化为本地时间 char* asctime(const struct tm* timeptr);//通过tm结构生成具有固定格式的时间字符串 char* ctime(const time_t *timer);//通过日历时间生成时间字符串
实例
时间转字符串
size_t strftime(char* strDest,size_t maxsize,const char* format,const struct tm *timeptr); time_t timer=time(NULL); char szbuf[256]={0}; strftime(szbuf,sizeof(szbuf),"%Y-%m-%d %H:%M:%S",localtime(&timer));
上面用了 time_t 获取了从1970年1月1日0时0分0秒到现在的秒数,
%Y是年
%m是月
%d是天
%H是时
%M是分
%S是秒
经过这段操作,就可以输出当前时间2022-4-24 17:33:38
因为今天还暂时用不到别的,所以先说这一个
实例2:判断当前时间在不在某时间段内
int huoqu() { time_t now_time; now_time = time(NULL); struct tm *local; local=localtime(&now_time); //获取当前系统时间 char buf[80]; strftime(buf,80,"%H0%M",local); if ((buf[0]-'0')*10+(buf[2]-'0')==20) { return 1; } else { return 0; } }
这行 if(........==20)可能乍一看看不懂
这行代码的意思是24时制小时数是晚上八点
可以判断当前时间在不在八点到九点之间
因为如果是八点到九点,时间肯定是20:xx
所以只要判断小时是不是20就行了
实例三:防沉迷系统
这个其实我之前发过,今天把它又改了一下,顺便发出来了
代码游戏部分有重复的部分,没有什么学习价值,可以自己复制玩玩
#include <iostream> #include <string> #include <iomanip> #include <time.h> #include<stdlib.h> #include<windows.h> #include<cstring> #include<conio.h> using namespace std; int sfz() { int a[18],i,n,b; printf("当前未进行认证\n"); printf("请输入身份证号:"); for(i=0;i<18;i++) scanf("%1d",&a[i]); n=a[6]*1000+a[7]*100+a[8]*10+a[9]; b=2022-n; if(b<18) return 0; else return 1; } int huoqu() { time_t now_time; now_time = time(NULL); struct tm *local; local=localtime(&now_time); //获取当前系统时间 char buf[80]; strftime(buf,80,"%H0%M",local); if ((buf[0]-'0')*10+(buf[2]-'0')==20) { return 1; } else { return 0; } } int jiancha() { time_t now_time; now_time = time(NULL); struct tm *local; local=localtime(&now_time); //获取当前系统时间 char buf[80]; strftime(buf,80,"%H0%M",local); if ((buf[0]-'0')*10+(buf[2]-'0')!=20) { return 0; } } int main() { system("color F0"); if (sfz()==0) { if (huoqu()==1) { start: cout<<" 21点"<<endl; cout<<"----------------------"<<endl; cout<<"输入1开始"<<endl; int n; cin>>n; if (n==1) { system("cls"); cout<<"开始"<<endl; //输入昵称 string name1,name2; cout<<"请输入玩家1昵称"<<endl; cin>>name1; cout<<"请输入玩家2昵称"<<endl; cin>>name2; /**/ string op1,op2; int n1=0,n2=0; int s1=0,s2=0; //玩家1 cout<<"请玩家1拿牌"<<endl; while (true) { cout<<"是否继续拿?(y/n)"<<endl; cin>>op1; if (op1=="y") { srand(time(NULL)); s1 += (rand()%(7-1+1)+1); cout<<"你的牌一共有"<<s1<<endl; n1++; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } else if (op1=="n") { cout<<"你一共拿了"<<n1<<"张牌"; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } break; } else { cout<<"请不要乱输!"; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } Sleep(3000); system("cls"); //玩家2 cout<<"请玩家2拿牌"<<endl; while (true) { cout<<"是否继续拿?(y/n)"<<endl; cin>>op2; if (op2=="y") { srand(time(NULL)); s2 += (rand()%(7-1+1)+1); cout<<"你的牌一共有"<<s2<<endl; n2++; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } else if (op1=="n") { cout<<"你一共拿了"<<n2<<"张牌"; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } break; } else { cout<<"请不要乱输!"; if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } if (jiancha()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(1000); exit(0); } } Sleep(3000); system("cls"); cout<<"正在统计....."<<endl; Sleep(1000); cout<<"玩家1总分数:"<<s1<<endl; cout<<"玩家2总分数:"<<s2<<endl; if (s1<=21 && s2<=21) { if (s1>s2) { cout<<"【"<<name1<<"】"<<"is the winner!!!"; cout<<"\n按a重来"; int chch = _getch(); if (chch==97) goto start; } if (s1==s2) { cout<<"【"<<name1<<"】"<<"and"<<"【"<<name2<<"】"<<"come out even!!!"; cout<<"\n按a重来"; int chch = _getch(); if (chch==97) goto start; } if (s1<s2) { cout<<"【"<<name2<<"】"<<"is the winner!!!"; cout<<"\n按a重来"; int chch = _getch(); if (chch==97) goto start; } } if(s1>21 && s2>21) { cout<<"两方都超过21分,"<<"【"<<name1<<"】"<<"and"<<"【"<<name2<<"】"<<"come out even!!!"; cout<<"\n按a重来"; int chch = _getch(); if (chch==97) goto start; } if (s1>21 && s2<=21) { cout<<"【"<<name2<<"】"<<"is the winner!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start; } if (s2>21 && s1<=21) { cout<<"【"<<name1<<"】"<<"is the winner!!!"; cout<<"\n按a重来"; int chch = _getch(); if (chch==97) goto start; } } } if (huoqu()==0) { cout<<"\n腾讯成长守护提醒您:\n根据国家防沉迷通知的相关要求和腾讯最新强化的防沉迷策略,由于您是未成年玩家,仅能在\n周五、周六、和法定节假日每日20时至21时登录游戏,在上述时间段外无法游戏,请注\n意休息。\n"; Sleep(3000); exit(0); } } if (sfz()==1) { start1: cout<<" 21点"<<endl; cout<<"----------------------"<<endl; cout<<" 输入1开始"<<endl; int n; cin>>n; if (n==1) { system("cls"); cout<<"开始"<<endl; //输入昵称 string name1,name2; cout<<"请输入玩家1昵称"<<endl; cin>>name1; cout<<"请输入玩家2昵称"<<endl; cin>>name2; /**/ string op1,op2; int n1=0,n2=0; int s1=0,s2=0; //玩家1 cout<<"请玩家1拿牌"<<endl; while (true) { cout<<"是否继续拿?(y/n)"<<endl; cin>>op1; if (op1=="y") { srand(time(NULL)); s1 += (rand()%(7-1+1)+1); cout<<"你的牌一共有"<<s1<<endl; n1++; } else if (op1=="n") { cout<<"你一共拿了"<<n1<<"张牌"; break; } else { cout<<"请不要乱输!"; } } Sleep(3000); system("cls"); //玩家2 cout<<"请玩家2拿牌"<<endl; while (true) { cout<<"是否继续拿?(y/n)"<<endl; cin>>op2; if (op2=="y") { srand(time(NULL)); s2 += (rand()%(7-1+1)+1); cout<<"你的牌一共有"<<s2<<endl; n2++; } else if (op1=="n") { cout<<"你一共拿了"<<n2<<"张牌"; break; } else { cout<<"请不要乱输!"; } } Sleep(3000); system("cls"); cout<<"正在统计....."<<endl; Sleep(1000); cout<<"玩家1总分数:"<<s1<<endl; cout<<"玩家2总分数:"<<s2<<endl; if (s1<=21 && s2<=21) { if (s1>s2) { cout<<"【"<<name1<<"】"<<"is the winner!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } if (s1==s2){ cout<<"【"<<name1<<"】"<<"and"<<"【"<<name2<<"】"<<"come out even!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } if (s1<s2){ cout<<"【"<<name2<<"】"<<"is the winner!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } } if(s1>21 && s2>21) { cout<<"两方都超过21分,"<<"【"<<name1<<"】"<<"and"<<"【"<<name2<<"】"<<"come out even!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } if (s1>21 && s2<=21) { cout<<"【"<<name2<<"】"<<"is the winner!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } if (s2>21 && s1<=21) { cout<<"【"<<name1<<"】"<<"is the winner!!!"; cout<<"\n按a重来\n"; int chch = _getch(); if (chch==97) goto start1; } } } return 0; }
好了,效果就是要先输入身份证号,再判断一下
如果是未成年,如果时间是晚上八点到九点之间,可以进入游戏,如果不在八点到九点之间,不能进入游戏
如果是成年人,直接进入游戏
结束
哈哈,做完了
大家应该对time.h也有了一些新的了解
拜拜
-
C++ 获取当前时间毫秒数
2020-06-03 10:45:20在window环境下: 1、精确到毫秒 #include "stdafx.h" #include <windows.h> #include <iostream>... /* 获取开始时间 */ time_start = GetTickCount(); //从操作系统启动经过的毫秒数在window环境下:
1、精确到毫秒#include "stdafx.h" #include <windows.h> #include <iostream> using namespace std; int main(int argc, _TCHAR* argv[]) { DWORD time_start, time_end; /* 获取开始时间 */ time_start = GetTickCount(); //从操作系统启动经过的毫秒数 Sleep(3000); time_end = GetTickCount(); cout << "Time = " << (time_end - time_start) << "ms\n "; return 0; }
#include <time.h> clock_t start,ends; start=clock(); Sleep(50); ends=clock(); cout<<ends-start<<endl;
time_t 获得时间只能精确到秒,clock_t 获得时间能够精确到毫秒
2、精确到秒unsigned long long Utils::GetCurrentTimeMsec() { #ifdef _WIN32 struct timeval tv; time_t clock; struct tm tm; SYSTEMTIME wtm; GetLocalTime(&wtm); tm.tm_year = wtm.wYear - 1900; tm.tm_mon = wtm.wMonth - 1; tm.tm_mday = wtm.wDay; tm.tm_hour = wtm.wHour; tm.tm_min = wtm.wMinute; tm.tm_sec = wtm.wSecond; tm.tm_isdst = -1; clock = mktime(&tm); tv.tv_sec = clock; tv.tv_usec = wtm.wMilliseconds * 1000; return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000); #else struct timeval tv; gettimeofday(&tv, NULL); return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000); #endif }
在Linux环境下
1. 精确到毫秒#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <unistd.h> int main(int argc, char *argv[]) { struct timeval time; /* 获取时间,理论到us */ gettimeofday(&time, NULL); printf("s: %ld, ms: %ld\n", time.tv_sec, (time.tv_sec*1000 + time.tv_usec/1000)); sleep(3); //延时 /* 重新获取 */ gettimeofday(&time, NULL); printf("s: %ld, ms: %ld\n", time.tv_sec, (time.tv_sec*1000 + time.tv_usec/1000)); exit(0); }
2. 精确到秒
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char *argv[]) { time_t t; struct tm *tmp; char buf2[64]; /* 获取时间 */ time(&t); tmp = localtime(&t); /* 转化时间 */ if (strftime(buf2, 64, "time and data: %r, %a %b %d, %Y", tmp) == 0) { printf("buffer length 64 is too small\n"); } else { printf("%s\n", buf2); } exit(0); }
-
C++获取当前时间(VSCode+minGW)
2021-09-06 10:37:06获取北京时间,加到图片的图片名 -
C++获取当前时间(北京时间)
2021-03-16 17:29:59C++获取当前时间 #include <iostream> #include <ctime> using namespace std; int main( ) { time_t now = time(0); cout << "1970 到目前经过秒数:" << now << endl; ... -
C++ 获取当前时间的年,月,日,以及时分秒
2021-08-20 14:32:09C++ 标准库没有提供所谓的日期类型,所以需要引入库ctime,即在顶部引入#include<ctime> 获取年月日,等tm 提供如下 struct tm { int tm_sec; // 秒,正常范围从 0 到 59 int tm_min; // 分,范围从 0 到 ... -
c++获取当前时间 并操作年月日
2020-07-23 19:27:57c++获取当前系统时间,并对获取到的时间进行处理操作 最近在公司将js代码转为c++代码,遇到了很多问题,在js中很多功能被封装,直接调用就行,非常方便。但是公司业务需求,需要转换,经常碰到一些功能在c++中不能... -
c/c++ 获取当前时间 精确到毫秒或者秒
2020-09-25 16:05:24C++获取当前时间,分别精确到ms和s 在window环境下: 1、精确到毫秒 // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> ... -
c++获取当前时间(年、月、日、星期几、时、分、秒、毫秒)
2022-03-04 16:01:56#include <string> #include<iostream> #include<windows.h> #include ...//过期时间 简单获取当前时间 CString strTime; CTime tm; tm = CTime::GetCurrentTime(); strTime = tm.Format("%Y年%m月%d日 %X "); -
用C++获取当前时间
2010-10-23 17:02:06This file contains a summary of what you will find in each of the files that make up your Example application. -
C++获取当前时间字符串
2017-12-29 12:25:42#include std::string GetNowTime() { time_t setTime; time(&setTime); tm* ptm = localtime(&setTime); std::string time = std::to_string(ptm->tm_year + 1900) + "/ -
c++ 获取当前时间--年月日、时分秒、毫秒
2021-01-03 16:36:22//获取当前时间 可精确到ms char tmpbuff[16]; /*年*/ sprintf(tmpbuff, "%d", st.wYear); std::string year = tmpbuff; /*月*/ sprintf(tmpbuff, "%d", st.wMonth); std::string month = tmpbuff; /*日*/ sprintf... -
C++ 获取当前时间毫秒数 GetTickCount64() 获取秒级time(NULL)
2021-09-15 11:15:45windows下 #include #include using namespace std; int main() { while (true) { //cout (NULL); //获取秒级 cout ()%3; //cout ; Sleep(1000); } return 0;... 参考文章:C++ 获取当前时间毫秒数 -
C++获取当前时间,并使用时间命名,输出txt数据文件
2020-05-29 13:35:11C++获取当前时间,并使用时间命名,输出txt数据文件 time_t nowtime = time(NULL); struct tm* p; p = gmtime(&nowtime); char filename[256] = { 0 }; time_flage = time_flage + 1; sprintf(filename, ... -
C++获取当前系统时间
2022-01-14 10:08:08在Linux环境下,c++获取当前系统时间的相关代码: #include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char *argv[]) { time_t t; struct tm *tmp; char buf2... -
c++获取当前日期时间字符串yyyymmddhhiiss
2022-05-16 16:55:04C++里获取当前时间的字符串的封装。 -
C/C++如何获取当前系统时间的实例详解
2020-12-26 08:20:31C/C++如何获取当前系统时间的实例详解 C库中与系统时间相关的函数定义在头文件中, C++定义在头文件中。 一、time(time_t*)函数 函数定义如下: time_t time (time_t* timer); 获取系统当前日历时间 UTC 1970-01... -
c++获取当前的时间
2022-03-21 18:05:14uint64_t getCurrentTime(); uint64_t getCurrentTime() { using namespace std::chrono; uint64_t ctime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();...} -
C++ 获取系统当前时间
2021-05-11 11:25:22C++ 获取系统当前时间c++ time函数_C++的日期和时间函数获取系统当前时间实例 c++ time函数_C++的日期和时间函数 C++ 标准库没有提供所谓的日期类型。C++ 继承了 C 语言用于日期和时间操作的结构和函数。为了使用... -
C++ 获取当前时间,并转换成string类型
2019-07-27 09:38:20// 在控制台输出当前时间 cout ; cout按任意键继续……"; // 以下代码是为了不闪屏退出 cin.clear(); cin.sync(); cin.get(); return 0; } 输出结果: 2019年07月27日09时34分44秒 按任意键继续…… ... -
C++获取当前时间 (std::chrono)
2020-02-28 20:25:19在C++11之前要获取当前时间,大多数情况下要使用C语言的time库: #include <iostream> #include<time.h> #include <sstream> int main() { time_t now = time(NULL); tm* tm_t = localtime(&... -
C++获取当前时间及计算当前时间距某个时间点的时间段
2020-01-23 16:06:141、获取系统时间: SYSTEMTIME sysTime; ///< 系统时间 GetLocalTime(&sysTime); strFileName.Format("%s\\%d_%d_%d_%d_%d_%d_%d.bmp",strFilePath, ... -
C++获取当前时间(年月日、时分秒、毫秒)
2018-09-14 09:23:38<p><strong>获取时间:</strong> 年-月-日(YYmmdd) 时:分:秒(HHMMSS) 毫秒(MS) 效率问题需要再优化 代码: #include #include #include using namespace std ; ... -
c++ 获取当前时间 精确到毫秒或者秒
2019-04-18 16:12:01C++获取当前时间,分别精确到ms和s 1、精确到毫秒 // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include <iostream> using ... -
c++ 获取当前时间(年月日时分秒)
2019-12-30 11:58:31#include <stdio.h> #include <windows.h> int main() { SYSTEMTIME st; GetLocalTime(&... printf("%d-%02d-%02d %02d:%02d:%02d",st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.w...