CTimeSpan 的疑问

戈壁上的月光 2011-04-12 04:29:40
想通过 CTimeSpan 类来得到两个时间的差

CTime time1;
.....
CTime time2;
....

CTimeSpan span = time1 - time2;

int len=span.GetMinutes(); //相减的秒数
怎么会报错?
error C2228: “.GetMinutes”的左侧必须有类/结构/联合类型
类型是“'unknown-type'”
急在线等!

...全文
121 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复
有一个CTime 是需要自己赋值的

CTime tm;
CString strTime;
int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
int IntOverTime;

tm=CTime::GetCurrentTime();
strTime="2010/01/02 02:20:20";
sscanf(strTime, "%d/%d/%d %d:%d:%d", &nYear,&nMonth,&nDay,&nHour,&nMinute,&nSecond);
CTime result(nYear,nMonth,nDay,nHour,nMinute,nSecond);
CTimeSpan timeSpan = tm - result;
IntOverTime=timeSpan.GetTotalMinutes();
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 king_hhuang 的回复:]
上面的用法是没有问题的
你的变量名好像编译器不识别啊,你换一个变量名,或者重新输一遍试试
把这段
long len=span.GetTotalSeconds();
重新敲一遍试试
还不行你就另见一个工程单独试试吧
[/Quote]
新建工程以上代码是可以的 见了鬼了
难道要把现在工程所有代码移到新的工程。。。汗!!
NightTravelDeity 2011-04-13
  • 打赏
  • 举报
回复

[Quote=引用 15 楼 ryueiketu 的回复:]
呵呵,费这劲干啥呀,用这个函数:GetTickCount();相当简单,好用。
[/Quote]
NightTravelDeity 2011-04-13
  • 打赏
  • 举报
回复
代码没问题,书写或环境有问题
ryueiketu 2011-04-13
  • 打赏
  • 举报
回复
呵呵,费这劲干啥呀,用这个函数:GetTickCount();相当简单,好用。
King_hhuang 2011-04-13
  • 打赏
  • 举报
回复
上面的用法是没有问题的
你的变量名好像编译器不识别啊,你换一个变量名,或者重新输一遍试试
把这段
long len=span.GetTotalSeconds();
重新敲一遍试试
还不行你就另见一个工程单独试试吧
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 king_hhuang 的回复:]
你那个程序是可以编译通过的,你把项目中的临时文件(ncb、aps、clw、opt)等删掉重新生成试试
[/Quote]
还是一样的错误 !
King_hhuang 2011-04-13
  • 打赏
  • 举报
回复
你那个程序是可以编译通过的,你把项目中的临时文件(ncb、aps、clw、opt)等删掉重新生成试试
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 king_hhuang 的回复:]
看看你是不是用了中文字符导致编译器不识别
[/Quote]
没有中文字符啊
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wuzongman 的回复:]
CTime time1;
.....
CTime time2;
....

CTimeSpan span = time1 - time2;

int len=span.GetTotalSeconds();
[/Quote]
就是这么用出错了!
戈壁上的月光 2011-04-13
  • 打赏
  • 举报
回复

if(nIDEvent == 1)
{
if(m_bServiceRunning)
{
m_nMinite++;
if (m_nMinite==15)
{
//统计数据、并写入数据库
int IntAllVeh=0;
int IntZhong=0;
int IntYYVeh=0;
int IntOnlineVeh=0;
int IntTaxiVeh=0;
int i,j;
int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
CString strTime;
CTime tmpTime;
CTime tm;
int IntOverTime=0;
CString strsql;
CTimeSpan timeSpan;
CTimeSpan span;

for (i=0;i<=p_Team[0].iAll;i++)
{
for (j=0;j<p_veh[0].iAll;j++)
{
tm=CTime::GetCurrentTime();
strTime=p_veh[j].StrDate +" " + p_veh[j].StrTime;
sscanf(strTime, "%d/%d/%d %d:%d:%d", &nYear,&nMonth,&nDay,&nHour,&nMinute,&nSecond); // 得到年
// 构造CTime变量
CTime result(nYear,nMonth,nDay,nHour,nMinute,nSecond);
timeSpan = tm - result;
IntOverTime=timeSpan.GetTotalMinutes(); //相减的分数
IntAllVeh++;
if ( IntOverTime<m_nMinite && p_veh[j].BlnLocate)
{
IntOnlineVeh++;
if (p_veh->IntTaxiStatus!=0)
{
IntYYVeh++;
}
if (p_veh->IntTaxiStatus==16)
{
IntZhong++;
}
}
strTime=p_veh[j].StrBusinessTime;
sscanf(strTime, "%d/%d/%d %d:%d:%d", &nYear,&nMonth,&nDay,&nHour,&nMinute,&nSecond); // 得到年

// 构造CTime变量
CTime yyTime(nYear,nMonth,nDay,nHour,nMinute,nSecond);
span = tm-yyTime;
IntOverTime=span.GetTotalMinutes(); //相减的分数
if ( IntOverTime<60 && p_veh[j].BlnLocate)
{
IntYYVeh++;
}
}
}
m_nMinite=0;
}
}
}
CDialog::OnTimer(nIDEvent);

izardMan 2011-04-12
  • 打赏
  • 举报
回复
CTime time1;
.....
CTime time2;
....

CTimeSpan span = time1 - time2;

int len=span.GetTotalSeconds();
戈壁上的月光 2011-04-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 huangcheng90 的回复:]
CTimeSpan::GetTotalMinutes
[/Quote]
已经定义了CTimeSpan的变量
你这个怎么用的?
戈壁上的月光 2011-04-12
  • 打赏
  • 举报
回复
我用的是2003,编译出错的一句是int len=span.GetMinutes();
注释掉就可以
奇怪!!!!
Dreadnought 2011-04-12
  • 打赏
  • 举报
回复
CTimeSpan::GetTotalMinutes
King_hhuang 2011-04-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 king_hhuang 的回复:]
不应该啊,不过如果你要计算总秒数
要用CTimeSpan::GetTotalMinutes
GetMinutes的范围是-59~59
[/Quote]
不好意思GetTotalMinutes 是总分钟
GetTotalSeconds 才是总秒数
HowToP2p 2011-04-12
  • 打赏
  • 举报
回复
我编译没错
King_hhuang 2011-04-12
  • 打赏
  • 举报
回复
看看你是不是用了中文字符导致编译器不识别
小石头0115 2011-04-12
  • 打赏
  • 举报
回复
相减的秒数貌似是:LONG GetTotalSeconds( ) const;
King_hhuang 2011-04-12
  • 打赏
  • 举报
回复
不应该啊,不过如果你要计算总秒数
要用CTimeSpan::GetTotalMinutes
GetMinutes的范围是-59~59

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧