Chinaunix首页 | 论坛 | 博客
  • 博客访问: 949950
  • 博文数量: 108
  • 博客积分: 3243
  • 博客等级: 中校
  • 技术积分: 964
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-15 22:09
文章分类

全部博文(108)

文章存档

2020年(2)

2019年(1)

2018年(2)

2017年(9)

2016年(20)

2015年(1)

2013年(1)

2012年(12)

2011年(28)

2010年(27)

2009年(4)

2008年(1)

分类: C/C++

2008-09-02 21:25:58

1 获取当前时间
CTime time = CTime::GetCurrentTime();
其中GetYear( ),GetMonth( ), GetDay( ), GetHour( ), GetMinute( ), GetSecond( ), GetDayOfWeek( ) 返回整型(int)对应项目
例:
int NowMonth = time1.GetMonth();
2 两个时间之间的比较
BOOL operator ==( CTime time ) const;
BOOL operator !=( CTime time ) const;
BOOL operator <( CTime time ) const;
BOOL operator >( CTime time ) const;
BOOL operator <=( CTime time ) const;
BOOL operator >=( CTime time ) const; 
例:
CTime t1 = CTime::GetCurrentTime();
CTime t2 = t1 + CTimeSpan( 1, 0, 0, 0 ); // 1 Day later
ASSERT( t1 != t2 );
ASSERT( t1 < t2 );
ASSERT( t1 <= t2 ); 
3 时间差
CTime operator +( CTimeSpan timeSpan ) const;
CTime operator - ( CTimeSpan timeSpan ) const;
CTimeSpan operator - ( CTime time ) const; 
例:
CTime t1( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
CTime t2( 1999, 3, 20, 22, 15, 0 ); // 10:15PM March 20, 1999
CTimeSpan ts = t2 - t1; // Subtract 2 Ctimes
ASSERT( ts.GetTotalSeconds() == 86400L );
ASSERT( ( t1 + ts ) == t2 ); // Add a CTimeSpan to a CTime.
ASSERT( ( t2 - ts ) == t1 ); // Subtract a CTimeSpan from a CTime. 
4 时间格式化
将当前时间格式化 CString date = time.Format("%Y-%m-%d %H:%M:%S %W-%A");
结果为:2006-10-13 17:23:47 41-Friday
 
阅读(2535) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Delphi多线程编程

给主人留下些什么吧!~~