//方案— 優(yōu)點(diǎn):僅使用C標(biāo)準(zhǔn)庫(kù);缺點(diǎn):只能精確到秒級(jí)
#include <time.h>
#include <stdio.h>
int main( void )
{
time_t t = time( 0 );
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t)
);
puts( tmp );
return 0;
}
//方案二 優(yōu)點(diǎn):能精確到毫秒級(jí);缺點(diǎn):使用了windows API
#include <windows.h>
#include <stdio.h>
int main( void )
{
SYSTEMTIME sys;
GetLocalTime( &sys );
printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d
星期%1d\n",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek);
return 0;
}
//方案三,優(yōu)點(diǎn):利用系統(tǒng)函數(shù),還能修改系統(tǒng)時(shí)間
#include<stdlib.h>
#include<iostream>
using namespace std;
void main()
{
system("time");
}
//方案四,將當(dāng)前時(shí)間折算為秒級(jí),再通過(guò)相應(yīng)的時(shí)間換算即可
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t now_time;
now_time =
time(NULL);
cout<<now_time;
return 0;
}
posted on 2009-07-30 13:41
老馬驛站 閱讀(399)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
c++