头文件<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 中国标准时间 |
Good content. Many thanks. Finasteride Terazosin Penis Enlargement
You reported this adequately! kratom powder
Incredible a good deal of wonderful advice. celexa medication
Great forum posts. Kudos! viagra
Appreciate it, An abundance of knowledge.
Amoxicillin Antibiotic Buy Online
Cheers. I like it! canadian online pharmacies
Seriously many of helpful advice. How To Withdraw From Cymbalta
Tips effectively used.! https://viagradjango.com/