如何将得到的系统时间拿来做文件名?
需要这样的 20030904 不是200394 不能把0去掉。

解决方案 »

  1.   

    CString sFileName = CTime::GetCurrentTime().Format("%Y%m%d");
      

  2.   

    如果不喜欢使用MFC,可以这样:
    time_t ltime = time(NULL);
    struct tm *stime = localtime(&ltime);
    int year = 1900 + stime->tm_year;
    int month = stime->tm_mon;
    int day = stime->tm_mday;char filename[9];
    sprintf(filename , "%d%02d%02d" , year , month , day);
      

  3.   

    搞错了一点:
    int month = 1 + stime->tm_mon;
    才对,其实还可以更简单:time_t now = time(0);
    char filename[9];
    strftime(filename , 9 , "%Y%m%d" , localtime(&now));
      

  4.   

    : steedhorse(晨星) 的方法不错!
      

  5.   

    CTime tm = CTime::GetCurrentTime();
    char filename[9];
    strftime(filename , 9 , "%s" , tm.Format("%Y-%m-%d"));