小弟新手,现在要对数据库的一些表进行操作,表名都是xx2008_10_6之类的,后面后缀就是时间的意思,
我的代码如下,
CTime   timetoday=CTime::GetCurrentTime();
CString   str ;
str = timetoday.Format("%Y_%m_%d");
这样的话str的值就是2008_10_06,
请问有没有什么方便的方法可以把2008_10_06转化成2008_10_6,
各位高手帮帮忙,谢谢了

解决方案 »

  1.   

    提取 y,m,d,然后再组合在一起。
      

  2.   

    str.Format(_T("%d_%d_%d"), timetoday.GetYear(), timetoday.GetMonth(), timetoday.GetDay());
      

  3.   

    呵呵,谢谢楼上的,
    有个疑问,如果单独提取d的话,结果就是str="05",
    想去掉0的话是不是还得判断有没有'0'的存在,是不是有点麻烦呀,
    就是想请教有没有方便一些的方法
      

  4.   

    str = timetoday.Format("%Y_%m_%d",timetoday.GetYear(),timetoday.GetMonth(),timetoday.GetDay());
      

  5.   

    CTime  timetoday=CTime::GetCurrentTime(); 
    CString  str,str1 ; 
    str = timetoday.Format("%d"); 
    int m;//申明一个整型
    m=atoi(str);//把字符串"06"转换成整型,这样就没"0"了
    str.Format("%d",m);//再把这个"6"转成十进制字符
    str1=timetoday.Format("%Y_%m_");//把年月放在str1里
    str1=str1+str;//把日加在年月后面
      

  6.   

    CTime  timetoday=CTime::GetCurrentTime(); 
    CString  str ;
    str.Format(_T("%d_%d_%d"),timetoday.GetYear(),timetoday.GetMonth(),timetoday.GetDay());