重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
#include cstdio
站在用戶的角度思考問題,與客戶深入溝通,找到昆玉網(wǎng)站設(shè)計與昆玉網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋昆玉地區(qū)。
#include ctime
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void printTime() {
struct tm t;? ?//tm結(jié)構(gòu)指針
time_t now;? //聲明time_t類型變量
time(now);? ? ? //獲取系統(tǒng)日期和時間
localtime_s(t, now);? ?//獲取當(dāng)?shù)厝掌诤蜁r間
? ?//格式化輸出本地時間
printf("年-月-日-時-分-秒:%d-%d-%d %d:%d:%d\n", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
}
int main(int argc, char** argv) {
printTime();
}
clock()函數(shù)
頭文件:time.h
作用:返回從程序執(zhí)行開始的時鐘周期數(shù)
返回值類型:clock_t型,為自定義的長整型
可以將其除以常數(shù)CLOCKS_PER_SEC再乘以1000以轉(zhuǎn)化為毫秒數(shù)。
CreateWaitableTimer,SetWaitableTimer;
WM_TIMER消息也是可以的
如果不是Windows,則可以用time函數(shù),需包含time.h
先申明下,這個是我轉(zhuǎn)百度知道的,經(jīng)常BAIDU一下,就OK了
#include stdio.h
#include time.h
void main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( rawtime );
timeinfo = localtime ( rawtime );
printf ( "\007The current date/time is: %s", asctime (timeinfo) );
exit(0);
}
=================
#include time.h -- 必須的時間函數(shù)頭文件
time_t -- 時間類型(time.h 定義)
struct tm -- 時間結(jié)構(gòu),time.h 定義如下:
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
time ( rawtime ); -- 獲取時間,以秒計,從1970年1月一日起算,存于rawtime
localtime ( rawtime ); -- 轉(zhuǎn)為當(dāng)?shù)貢r間,tm 時間結(jié)構(gòu)
asctime ()-- 轉(zhuǎn)為標(biāo)準ASCII時間格式:
星期 月 日 時:分:秒 年
=========================================
你要的格式可這樣輸出:
printf ( "%4d-%02d-%02d %02d:%02d:%02d\n",1900+timeinfo-tm_year, 1+timeinfo-tm_mon,
timeinfo-tm_mday,timeinfo-tm_hour,timeinfo-tm_min,timeinfo-tm_sec);
就是直接打印tm,tm_year 從1900年計算,所以要加1900,
月tm_mon,從0計算,所以要加1
其它你一目了然啦。
用clock就到毫秒了. 它是直接返回毫秒.
#include stdio.h
#include stdlib.h
#include time.h
int main()
{
clock_t start, finish;
double elapsed_time;
start=clock();
finish=clock();
elapsed_time = finish-start;
}