标准C语言各种时间函数用法,使用c语言标准库中的时间函数
#include?
#include?
int?main(void){
time_t?start,?finish,?now;
struct?tm?*ptr;
char?*c,?buf1[80];
double?duration;
//記錄程序開始的時間
start?=?time(0);
//記錄當前時間,以另一種方式調用time()
time(&now);
//將time_t值轉換成tm類型的結構
ptr?=?localtime(&now);
//創建并顯示一個包含當前時間的格式字符串
c?=?asctime(ptr);
puts(c);
getc(stdin);
//使用strftime()函數創建多個不同的格式化時間版本
strftime(buf1,?80,?"This?is?week?%U?of?the?year?%Y",?ptr);
puts(buf1);
getc(stdin);
strftime(buf1,?80,?"Today?is?%A,?%x",?ptr);
puts(buf1);
getc(stdin);
strftime(buf1,?80,?"It?is?%M?minutes?past?hour?%I.",?ptr);
puts(buf1);
getc(stdin);
//獲取當前時間和計算程序執行時間
finish?=?time(0);
duration?=?difftime(finish,?start);
printf("\nProgram?execution?time?using?time()?=?%f?seconds.",?duration);
//使用clock()計算程序執行時間,并打印出來。
printf("\nProgram?execution?time?using?clock()?=?%ld?thousandths?of?sec.",?clock());
return?0;
}
總結
以上是生活随笔為你收集整理的标准C语言各种时间函数用法,使用c语言标准库中的时间函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java string isempty,
- 下一篇: matlab 工具 安装包下载地址,安装