通過vs2008編譯運行
#include <iostream>
#include <string>
#include<time.h>//必須包含time.h
int main()
{
struct tm *tm;//需要定義tm結構體,存放時間信息
time_t now;
now = time(NULL);//注意調用方式
tm = localtime( static_cast<const time_t*>(&now) );//需要傳遞time_t地址
printf("%02d:%02d:%02d %02d/%02d/%4d\n"
,tm->tm_hour,tm->tm_min,tm->tm_sec,tm->tm_mday
,tm->tm_mon+1,tm->tm_year+1900);//月份要加上1,年份要加上1900
system("pause");
return 0;
}