VC中CTime的用法时间操作.docxVIP

  • 2
  • 0
  • 约1.64千字
  • 约 3页
  • 2021-01-06 发布于山东
  • 举报
VC++ 中 CTime 的用法 时间操作 VC++ 中 CTime 的几种用法:获得当前日期和时间 CTime tm=CTime::GetCurrentTime();CString str=tm.Format(%Y-%m-%d); 在 VC 中,我们可以借助 CTime 时间类,获取系统当前日期,具体使用方法如下: CTime t = CTime::GetCurrentTime(); // 获取系统日期 int d=t.GetDay(); // 获得几号 int y=t.GetYear(); // 获取年份 int m=t.GetMonth(); // 获取当前月份 int h=t.GetHour(); // 获取当 前为几时 int mm=t.GetMinute(); // 获取分钟 int s=t.GetSecond(); // 获取秒 int w=t.GetDayOfWeek(); // 获取 星期几,注意 1 为星期天, 7 为星期六如果想计算两段时间 的差值,可以使用 CTimeSpan 类,具体使用方法如下: CTime t1( 1999, 3, 19, 22, 15, 0 );CTime t = CTime::GetCurrentTime();CTimeSpan span=t-t1; // 计算当 前系统时间与时间 t1 的间隔 int i

文档评论(0)

1亿VIP精品文档

相关文档