vc字符格式转化为时间

//字符格式转化为时间,真:加一天;假:减一天   
//字符格式转化为时间
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重载了比较操作符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值