码迷,mamicode.com
首页 > 其他好文 > 详细

localtime和localtime_r的差别

时间:2014-12-19 16:01:25      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

#include <cstdlib>

#include <iostream>

#include <time.h>

#include <stdio.h>


using namespace std;


int main(int argc, char *argv[])

{

    time_t tNow =time(NULL);

    time_t tEnd = tNow + 2500;


    //在这里修改程序

    //struct tm* ptm = localtime(&tNow);

    //struct tm* ptmEnd = localtime(&tEnd);

    struct tm* ptm = new struct tm[sizeof(struct tm)];

    struct tm* ptmEnd = new struct tm[sizeof(struct tm)];

    localtime_r(&tNow, ptm);

    localtime_r(&tEnd, ptmEnd);


    char szTmp[50] = {0};

    strftime(szTmp,50,"%H:%M:%S",ptm);

    char szEnd[50] = {0};

    strftime(szEnd,50,"%H:%M:%S",ptmEnd);

    printf("%s \n",szTmp);

    printf("%s \n",szEnd);



    system("PAUSE");

    return 0;

}


localtime和localtime_r的差别

标签:

原文地址:http://my.oschina.net/u/923534/blog/358033

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!