此文就用一个程序表示,相信只要是学过C语言的都能看得懂的。

  1. // CTimeTest.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "atltime.h"
  5. #include <iostream>
  6. using namespace std;
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9. CTime strTime ;//用于将CTime对象格式化为字符串
  10. CTime curTime  = CTime::GetCurrentTime() ;//获取当前的时间并保存到curTime
  11. int nYear = curTime.GetYear() ;
  12. int nMonth = curTime.GetMonth() ;
  13. int nDay = curTime.GetDay() ;
  14. int nHour = curTime.GetHour() ;
  15. int nMin = curTime.GetMinute() ;
  16. int nSec = curTime.GetSecond() ;
  17. cout << "输出当前时间:" << endl ;
  18. cout << nYear << "年"
  19. << nMonth<< "月"
  20. << nDay  << "日"
  21. << nHour << "时"
  22. << nMin<< "分"
  23. << nSec  << "秒" << endl;
  24. //为计算时间差设置一个起始时间
  25. CTime startTime = CTime(2010,10,31,12,12,12) ;
  26. cout << "起始时间:" << endl ;
  27. cout << startTime.GetYear() << "年"
  28. <<startTime.GetMonth() << "月"
  29. <<startTime.GetDay()   << "日"
  30. <<startTime.GetHour()  << "时"
  31. <<startTime.GetMinute()<< "分"
  32. <<startTime.GetSecond()<< "秒"
  33. << endl ;
  34. //计算时间差
  35. CTimeSpan timeSpan ;
  36. timeSpan = curTime - startTime ;
  37. cout << "两时时间差" << endl ;
  38. cout<<timeSpan.GetDays()<<"天"
  39. <<timeSpan.GetHours()<<"小时"
  40. <<timeSpan.GetMinutes()<<"分"
  41. <<timeSpan.GetSeconds()<<"秒"
  42. <<endl ;
  43. cout<<"总小时数:"<<timeSpan.GetTotalHours()<<"小时"<<endl ;
  44. cout<<"总分钟数:"<<timeSpan.GetTotalMinutes()<<"分"<<endl ;
  45. cout<<"总秒数:"<<timeSpan.GetTotalSeconds()<<"秒"<<endl ;
  46. //// 将当前时间 curTime 对象格式化为字符串
  47. //strTime = curTime.Format(_T("%Y-%m-%d %H:%M:%S"));
  48. //// 输出格式化字符串,由于字符串使用 Unicode 字符,所以要使用 wcout 输出
  49. //wcout<<(LPCTSTR)strTime<<endl;
  50. getchar() ;
  51. return 0;
  52. }

运行结果如下:

最新文章

  1. 常用 meta 整理
  2. 将已有项目提交到github/从github上pull到本地
  3. unity, 顶点对齐
  4. 通过微信分享链接,后面会被加上from=singlemessage&amp;isappinstalled=1可能导致网页打不开
  5. 剑指 offer set 6 打印从 1 到 N 的所有数
  6. 【HDU3065】 病毒侵袭持续中(AC自动机)
  7. Mongodb 条件查询
  8. Dalvik指令集
  9. 《C程序设计语言》 squeeze函数(从字符串s中删除字符c)
  10. idea bug集合
  11. python/*args和**kwargs
  12. 对于 Netty ByteBuf 的零拷贝(Zero Copy) 的理解
  13. PHP -- 七牛云 在线视频 获取某一帧作为封面图
  14. 02:MongoDB操作
  15. jdbc java远程连接mysql数据库服务器
  16. 【Ubuntu】Windows 远程桌面连接ubuntu及xrdp的一些小问题(远程桌面闪退、连接失败、tab补全功能,无菜单栏,error - problem connecting )【转】
  17. arcgis api for JavaScript _加载三维图层(scene layer)
  18. maven配置(myeclipse版)
  19. hdu2364之BFS
  20. css3图片响应式布局

热门文章

  1. JAVA8之日期操作详解
  2. 【备忘录】ORACLE数据库每日计划EXPDP备份
  3. logback.xml 配置详解(转)
  4. CentOS 7下安装IDL 8.2
  5. 获取网卡速率,cpu使用率
  6. Android源码开发利器——Java源码调试(基于4.1.2)
  7. poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!
  8. 20190716NOIP模拟赛T1 礼物(概率dp+状压)
  9. 灰度图像--图像分割 Sobel算子,Prewitt算子和Scharr算子平滑能力比较
  10. HDU 5894 hannnnah_j’s Biological Test ——(组合数)