头文件<ctime>定义了表示时间的数据类型:
tm结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/* * A structure for storing all kinds of useful information about the * current (or another) time. */ struct tm { int tm_sec; /* Seconds: 0-59 (K&R says 0-61?) */ int tm_min; /* Minutes: 0-59 */ int tm_hour; /* Hours since midnight: 0-23 */ int tm_mday; /* Day of the month: 1-31 */ int tm_mon; /* Months *since* january: 0-11 */ int tm_year; /* Years since 1900 */ int tm_wday; /* Days since Sunday (0-6) */ int tm_yday; /* Days since Jan. 1: 0-365 */ int tm_isdst; /* +1 Daylight Savings Time, 0 No DST, * -1 don't know */ }; |
time_t类型定义
1 |
typedef long time_t; |
clock_t类型定义
1 |
typedef long clock_t; |
<ctime>中函数有:
asctime() 将tm类型转换成字符串的类型
clock()? 返回clock_t类型的cpu时间
ctime() 将time_t类型转换成字符串的类型
difftime()? 计算两个time_t时间之间的差值
gmtime()? 将time_t转换成tm结构变量
localtime()? 将time_t转换成tm结构变量,使用当地时间
mktime()? 将tm结构变量转换成time_t
strftime(),wcsftime()? 按照指定的格式将tm结构变量转换成字符串
time()? 返回当前时间的time_t变量
格式代输出时间:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//梁笔记 //https://zouzhongliang.com #include <iostream> #include <ctime> using namespace std; int main() { time_t now = time(NULL); tm* NowTime = gmtime(&now); char strTime[255]; strftime(strTime,255,"%Y年%m月%d日 %H时%M分%S秒 %A %z",NowTime); cout<<strTime<<endl; return 0; } |
格式化时间输出:
1 |
2019年06月26日 09时46分11秒 Wednesday 中国标准时间 |
You made the point! fluconazole cream
Cheers! Wonderful information. fluconazole tablets
You reported that very well. fluconazole cream
Very well voiced truly! . diflucan
Thank you, Useful information. fluconazole bnf
You made the point. buy cialis online
Incredible many of valuable data! canadian cialis
Amazing lots of useful knowledge. armodafinil vs modafinil
Incredible tons of beneficial material. cialis 20 mg
Kudos, I value this. cbd oil
Reliable data. Thanks! viagra for sale
You revealed it adequately! propranolol
Wonderful stuff. With thanks. viagra for women
Whoa all kinds of terrific data! finasteride generic
Seriously loads of amazing material! canada drug pharmacy
Wonderful material. Thanks a lot! inderal medication
You explained this terrifically. canadian online pharmacies
Incredible tons of very good knowledge! tadalafil
Thanks a lot, Helpful information. what is cbd oil
Whoa a good deal of fantastic material! https://viagradocker.com/