CSDN博客

img firerain

C++读取系统时间

发表于2004/11/4 13:26:00  2970人阅读

分类: 积累

time_t time(time_t *timer);                 //得到系统时间

struct tm *gmtime(const time_t *timer);     //转化成tm格式

struct tm *localtime(const time_t *timer);  //有时区校正的

char *asctime(const struct tm *timeptr);    //得到 Wed Jan 02 02:03:55 1980/n/0 标准GSM格式时间字符串

size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr); //根据格式字符串生成字符串。

示例:
char     today[32]  ="";
char     second[32]  ="";
tm       *temptm;
time_t   temptime;
temptime = time(0);
temptm   = localtime(&temptime);
sprintf(today,"%d-%02d-%02d",temptm->tm_year+1900,temptm->tm_mon+1,temptm->tm_mday);
sprintf(second,"%02d:%02d:%02d",temptm->tm_hour,temptm->tm_min,temptm->tm_sec);
cout << "Time:" << second << endl;

阅读全文
0 0

相关文章推荐

img
取 消
img