【VS开发】CTime和CTimeSpan使用
2024-10-07 00:57:25
此文就用一个程序表示,相信只要是学过C语言的都能看得懂的。
- // CTimeTest.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "atltime.h"
- #include <iostream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- CTime strTime ;//用于将CTime对象格式化为字符串
- CTime curTime = CTime::GetCurrentTime() ;//获取当前的时间并保存到curTime
- int nYear = curTime.GetYear() ;
- int nMonth = curTime.GetMonth() ;
- int nDay = curTime.GetDay() ;
- int nHour = curTime.GetHour() ;
- int nMin = curTime.GetMinute() ;
- int nSec = curTime.GetSecond() ;
- cout << "输出当前时间:" << endl ;
- cout << nYear << "年"
- << nMonth<< "月"
- << nDay << "日"
- << nHour << "时"
- << nMin<< "分"
- << nSec << "秒" << endl;
- //为计算时间差设置一个起始时间
- CTime startTime = CTime(2010,10,31,12,12,12) ;
- cout << "起始时间:" << endl ;
- cout << startTime.GetYear() << "年"
- <<startTime.GetMonth() << "月"
- <<startTime.GetDay() << "日"
- <<startTime.GetHour() << "时"
- <<startTime.GetMinute()<< "分"
- <<startTime.GetSecond()<< "秒"
- << endl ;
- //计算时间差
- CTimeSpan timeSpan ;
- timeSpan = curTime - startTime ;
- cout << "两时时间差" << endl ;
- cout<<timeSpan.GetDays()<<"天"
- <<timeSpan.GetHours()<<"小时"
- <<timeSpan.GetMinutes()<<"分"
- <<timeSpan.GetSeconds()<<"秒"
- <<endl ;
- cout<<"总小时数:"<<timeSpan.GetTotalHours()<<"小时"<<endl ;
- cout<<"总分钟数:"<<timeSpan.GetTotalMinutes()<<"分"<<endl ;
- cout<<"总秒数:"<<timeSpan.GetTotalSeconds()<<"秒"<<endl ;
- //// 将当前时间 curTime 对象格式化为字符串
- //strTime = curTime.Format(_T("%Y-%m-%d %H:%M:%S"));
- //// 输出格式化字符串,由于字符串使用 Unicode 字符,所以要使用 wcout 输出
- //wcout<<(LPCTSTR)strTime<<endl;
- getchar() ;
- return 0;
- }
运行结果如下:
最新文章
- 常用 meta 整理
- 将已有项目提交到github/从github上pull到本地
- unity, 顶点对齐
- 通过微信分享链接,后面会被加上from=singlemessage&;isappinstalled=1可能导致网页打不开
- 剑指 offer set 6 打印从 1 到 N 的所有数
- 【HDU3065】 病毒侵袭持续中(AC自动机)
- Mongodb 条件查询
- Dalvik指令集
- 《C程序设计语言》 squeeze函数(从字符串s中删除字符c)
- idea bug集合
- python/*args和**kwargs
- 对于 Netty ByteBuf 的零拷贝(Zero Copy) 的理解
- PHP -- 七牛云 在线视频 获取某一帧作为封面图
- 02:MongoDB操作
- jdbc java远程连接mysql数据库服务器
- 【Ubuntu】Windows 远程桌面连接ubuntu及xrdp的一些小问题(远程桌面闪退、连接失败、tab补全功能,无菜单栏,error - problem connecting )【转】
- arcgis api for JavaScript _加载三维图层(scene layer)
- maven配置(myeclipse版)
- hdu2364之BFS
- css3图片响应式布局
热门文章
- JAVA8之日期操作详解
- 【备忘录】ORACLE数据库每日计划EXPDP备份
- logback.xml 配置详解(转)
- CentOS 7下安装IDL 8.2
- 获取网卡速率,cpu使用率
- Android源码开发利器——Java源码调试(基于4.1.2)
- poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!
- 20190716NOIP模拟赛T1 礼物(概率dp+状压)
- 灰度图像--图像分割 Sobel算子,Prewitt算子和Scharr算子平滑能力比较
- HDU 5894 hannnnah_j’s Biological Test ——(组合数)