int time = 1324969198;
如何将time转成时间,然后以字符串的形式进行存储呢?

解决方案 »

  1.   

    struct  tm  *localtime(const  time_t  *timer)
      

  2.   


    int n = 1324969198;
    CTime tm(n);
    CString str = tm.Format(_T("%Y-%m-%d-%H:%M"));具体的日期格式自己设定,可以查看CTime中的Format函数
      

  3.   


    int n = 1324969198;
    CTime tm(n);
    CString str = tm.Format(_T("%Y-%m-%d-%H:%M"));
      

  4.   

    char *transGivenTimeToStr(int iGivenTime)
    {
    time_t tmpTime = iGivenTime;
    struct tm *tmVar = localtime(&tmpTime);
    static char timeBuff[MAXTIMESTRLEN];
    sprintf(timeBuff, "%04d-%02d-%02d_%02d_%02d_%02d",
    tmVar->tm_year + 1900, tmVar->tm_mon + 1, tmVar->tm_mday,
    tmVar->tm_hour, tmVar->tm_min, tmVar->tm_sec);
    return timeBuff;
    }你直接复制一下。
      

  5.   


    int n = 1324969198;
    CTime tm(n);
    CString str = tm.Format(_T("%Y-%m-%d-%H:%M"));
      

  6.   


    感谢 dahaiI0的帮助,同时也谢谢热心的朋友哦。
    xiaoxiaoyu85 你的方法似乎是标准C++里实现的方法,不是MFC的哦。不过一样要谢谢