c语言的时间怎么处理函数,C语言时间处理函数

头文件定义了表示时间的数据类型:

tm结构

tm时间结构定义

C++

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.

*/

structtm

{

inttm_sec;/* Seconds: 0-59 (K&R says 0-61?) */

inttm_min;/* Minutes: 0-59 */

inttm_hour;/* Hours since midnight: 0-23 */

inttm_mday;/* Day of the month: 1-31 */

inttm_mon;/* Months *since* january: 0-11 */

inttm_year;/* Years since 1900 */

inttm_wday;/* Days since Sunday (0-6) */

inttm_yday;/* Days since Jan. 1: 0-365 */

inttm_isdst;/* +1 Daylight Savings Time, 0 No DST,

* -1 don't know */

};

time_t类型定义

long 类型别名

C++

1

typedeflongtime_t;

clock_t类型定义

long 类型别名

C++

1

typedeflongclock_t;

中函数有:

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变量

格式代输出时间:

格式化输出时间

C++

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

//梁笔记

//https://zouzhongliang.com

#include

#include

usingnamespacestd;

intmain(){

time_tnow=time(NULL);

tm*NowTime=gmtime(&now);

charstrTime[255];

strftime(strTime,255,"%Y年%m月%d日 %H时%M分%S秒 %A %z",NowTime);

cout<

return0;

}

格式化时间输出:

格式化后时间输出

C++

1

2019年06月26日09时46分11秒Wednesday中国标准时间

相关文章:标准c时间与日期函数asctime() 时间文本格式 clock() 返回自程序开始运行所经过的时间 ctime() 返回特定格式时间 difftime() 两时刻的间隔 gmtime() 返回指向当前格林威治时间的指针 localtime() 返回指向当前时间的指针...

difftime()函数difftimedifftime()函数difftime 语法: #include double difftime( time_t time2, time_t time1 ); 功能:函数返回时间参数time2和time1之差的秒数表示。...

gmtime()函数gmtimegmtime()函数gmtime 语法: #include struct tm *gmtime( const time_t *time ); 功能:函数返回给定的统一世界时间(通常是格林威治时间),如果系统不支持统一世界时间系统返回NULL。 警告!...

localtime()函数localtimelocaltime()函数localtime 语法: #include struct tm *localtime( const time_t *time ); 功能:函数返回本地日历时间。警告!...

mktime()函数mktimemktime()函数mktime 语法: #include time_t mktime( struct tm *time ); 功能:函数转换参数time 类型的本地时间至日历时间,并返回结果。如果发生错误,返回-1。...

strftime()函数strftimestrftime()函数strftime 语法: #include size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time ); 功能:函数按照参数fmt所设定格式将time类型的参数格式化为日期时间信息,然后存储在字符串str中(至多maxsize 个字符)。用于设定时间不同类型的代码为:...

time()函数timetime()函数time 语法: #include time_t time( time_t *time ); 功能: 函数返回当前时间,如果发生错误返回零。如果给定参数time ,那么当前时间存储到参数time中。...

内存操作函数string>和中定义了内存操作函数,以下是常用的内存操作函数。void* memchr(void* __p, int __c, size_t __n);在内存中查找指定字符串int memcmp(const void*, const void*, size_t);比较两块内存中的字符void* memcpy(void*, const void*, size_t);拷贝源内存块至目的内存块void* memmove(void*, const void*, size_t);移动源内存块至目的内存块void*...

系统控制函数定义了系统控制函数void abort();异常终止程序void exit(int status);终止当前程序int system(char* command);执行shell命令写一个系统控制函数的调用,用到system()函数...

字符串处理函数实例详解C++字符处理函数都定义在和中,以下列出字符处理函数并解释。sprintf(),vsprintf()  输出格式数据至指定字符串strcat(),wcscat(),strncat(),wcsncat()  串接两个字符串strchr(),wcschr(),strrchr(),wcsrchr()  在字符串中查找指定的字符strcmp(),wcscmp(),strncmp(),wcsncmp()  比较两个字符串的大小srtcpy(),wcscpy(),strncpy(),wcsncpy()  将字符串拷贝到另外一个字符串strcspn(),wcscspn()   在字符串中查找指定子串中任意字符的出现位置strerror()   返回错误号对应的错误信息strlen(),wcslen()   返回字符串的长度strpbrk(),wcspbrk()  在字符串中查找指定子串中任意字符,并返回该位置的指针strspn(),wcsspn()  在字符串中查找指定子串的出现位置strstr(),wcsstr()    在字符串中查找指定子串的出现位置,并返回该位置的指针strtok(),wcstok()   用来拆分字符串,返回下一个子串字符串处理函数拆分字符串例:...

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值