localtime和localtime_r的差異

#include <cstdlib>ios

#include <iostream>spa

#include <time.h>io

#include <stdio.h>stream


using namespace std;gc


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

{im

    time_t tNow =time(NULL);di

    time_t tEnd = tNow + 2500;time


    //在這裏修改程序new

    //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;

}

相關文章
相關標籤/搜索