现在的位置: 首页 > 综合 > 正文

vc字符格式转化为时间

2013年08月04日 ⁄ 综合 ⁄ 共 1002字 ⁄ 字号 评论关闭
//字符格式转化为时间,真:加一天;假:减一天   
//字符格式转化为时间
CString CGrossProfitRatioReportDlg::StrToDate(CString strTime,bool bAddOrPlus)
{
    CString  str(strTime);
    int   year,month,day,hour,minite,second;  
    sscanf(str,"%d-%d-%d   %d:%d:%d",&year,&month,&day,&hour,&minite,&second);
    COleDateTime time(year,month,day,hour,minite,second);
    COleDateTimeSpan Oneday(1);//一天时差
    if (bAddOrPlus)
    {
      time   +=   Oneday;//第二天了
    }
    else
    {
      time   -=   Oneday;//前一天了
    }
    CString strDate;  
    strDate=time.Format("%Y-%m-%d");
    return strDate;
}

2.

CString   str("2005-8-25   14:00:35");  
  int   nYear,   nMonth,   nDay,   nHour,   nMinite,   nSecond;  
  sscanf(str,   "%d-%d-%d   %d:%d:%d",  
                        &nYear,   &nMonth,   &nDay,   &nHour,   &nMinite,   &nSecond);  
  CTime   time(nYear,   nMonth,   nDay,   nHour,   nMinite,   nSecond);Top

3.

直接用COleDateTime,CTime的功能COleDateTime都有.  
   
  COleDateTime   oleTime1   =   COleDateTime::GetCurrentTime();  
  COleDateTime   oleTime2;  
  CString   str=   "2005-01-01   12:12:12"  
  oleTime2.ParseDateTime(str);  
   
  if   (oleTime2   >   oleTime)//COleDateTime重载了比较操作符

抱歉!评论已关闭.