- 浏览: 353231 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (335)
- C++ (190)
- 设计模式 (43)
- 数据库技术 (5)
- 网络编程 (11)
- 自动化测试 (6)
- Linux (13)
- OpenSSL (10)
- MS Crypt API (5)
- SCM (2)
- English (4)
- Android (10)
- EMV规范 (1)
- Saturn Platform (0)
- C (10)
- SQL (2)
- ASP.NET (3)
- 英语口语学习 (3)
- 调试工具 (21)
- 编译技术 (5)
- UML (1)
- 项目管理 (5)
- 敏捷开发 (2)
- Http Server (6)
- 代码审查、代码分析 (5)
- 面试基础 (10)
- 重点知识 (16)
- STL (6)
- Efficient C++资料 (8)
- 数据结构和算法 (7)
- 读书笔记 (0)
- 开源项目 (4)
- 多线程 (2)
- Console App (6)
- 个人开源项目 (4)
- IBM DevelopWorks (4)
- Java (16)
- 内存泄漏相关调试和检测 (13)
- 软件测试相关技术 (2)
- C# (11)
- Apple Related (1)
- 软件测试和管理 (2)
- EMV (1)
- Python (1)
- Node.js (6)
- JavaScript (5)
- VUE (1)
- Frontend (1)
- Backend (4)
- RESTful API (3)
- Firebase (3)
最新评论
-
u013189503:
来个密码吧
[C++][Logging] 项目中写日志模块的实现 -
wyf_vc:
来个密码啊!!
[C++][Logging] 项目中写日志模块的实现
void GetTime_Case_1() { // #include // #include //方案— :能精确到毫秒级并且使用简洁方便; SYSTEMTIME cTime; //获取系统时间类 CString TimeString; //转换 char cBuffer[100] = {0}; GetLocalTime(&cTime); //获取本地时间 TimeString.Format(_T("%4d-%2d-%2d %2d:%2d:%2d") //格式化输出到CString ,Time.wYear ,Time.wMonth ,Time.wDay ,Time.wHour ,Time.wMinute ,Time.wSecond); sprintf(cBuffer,"%4d-%2d-%2d %2d:%2d:%2d \n",//格式化输出到cBuffer Time.wYear, Time.wMonth, Time.wDay, Time.wHour, Time.wMinute, Time.wSecond); }
void GetTime_Case_1() { // #include // #include //方案二 :仅使用C标准库;但是只能精确到秒级 time_t GetTime = time(0); char cBuffer[64]; strftime( cBuffer, sizeof(cBuffer), "%Y/%m/%d %X %A 本?年?第?%j天?%z",localtime(&GetTime) ); /* size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr); 根据格式字符串生成字符串。 struct tm *localtime(const time_t *timer); 取得当地时间,localtime获取的结果由结构tm返回 返回的字符串可以依下列的格式而定: %a 星期几的缩写。Eg:Tue %A 星期几的全名。 Eg: Tuesday %b 月份名称的缩写。 %B 月份名称的全名。 %c 本地端日期时间较佳表示字符串。 %d 用数字表示本月的第几天 (范围为 00 至 31)。日期 %H 用 24 小时制数字表示小时数 (范围为 00 至 23)。 %I 用 12 小时制数字表示小时数 (范围为 01 至 12)。 %j 以数字表示当年度的第几天 (范围为 001 至 366)。 %m 月份的数字 (范围由 1 至 12)。 %M 分钟。s %p 以 ''AM'' 或 ''PM'' 表示本地端时间。 %S 秒数。 %U 数字表示为本年度的第几周,第一个星期由第一个周日开始。 %W 数字表示为本年度的第几周,第一个星期由第一个周一开始。 %w 用数字表示本周的第几天 ( 0 为周日)。 %x 不含时间的日期表示法。 %X 不含日期的时间表示法。 Eg: 15:26:30 %y 二位数字表示年份 (范围由 00 至 99)。 %Y 完整的年份数字表示,即四位数。 Eg:2008 %Z(%z) 时区或名称缩写。Eg:中国标准时间 %% % 字符。 */ }
#include <time.h> time_t t_time = time(0); tm localTM; localtime_s(&localTM, &t_time); cout<<localTM.tm_year+1900<<"-"<<localTM.tm_mon+1<<"-"<<localTM.tm_mday; cout<<"-"<<localTM.tm_hour<<":"<<localTM.tm_min<<":"<<localTM.tm_sec<<" "; 输出结果如下: 2011-7-8-14:40:28 /* "tm_sec" - 秒数 "tm_min" - 分钟数 "tm_hour" - 小时 "tm_mday" - 月份中的第几日 "tm_mon" - 年份中的第几个月,从 0 开始表示一月 "tm_year" - 年份,从 1900 开始 "tm_wday" - 星期中的第几天 "tm_yday" - 一年中的第几天 "tm_isdst" - 夏令时当前是否生效 注释:月份从 0(一月)到 11(十二月),星期数从 0(星期天)到 6(星期六)。 */ //获取当前路径的简单方法 #include <direct.h> string GetFileMainPath() { char buffer[256]; _getcwd(buffer, 256); string strTemp = buffer; return strTemp; }
//获取时间间隔 //方法一 #include <time.h> clock_t m_BeginTime; clock_t m_EndTime; m_BeginTime = clock(); Sleep(123); m_EndTime = clock(); printf("Execute Time: %.3f seconds\n", difftime(m_EndTime, m_BeginTime)/CLOCKS_PER_SEC); //方法二 SYSTEMTIME sTime1; SYSTEMTIME sTime2; ... ... ULARGE_INTEGER fTime1;/*FILETIME*/ ULARGE_INTEGER fTime2;/*FILETIME*/ SystemTimeToFileTime(&sTime1,(FILETIME*)&fTime1); SystemTimeToFileTime(&sTime2,(FILETIME*)&fTime2); unsigned __int64 dft=fTime2.QuadPart-fTime1.QuadPart;
使用CTime类(获取系统当前时间,精确到秒)
http://www.cnblogs.com/lujin49/p/4624971.html
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm.Format("现在时间是%Y年%m月%d日 %X"); MessageBox(str,NULL,MB_OK);a,从CTimet中提取年月日时分秒 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为星期六b,计算两段时间的差值,可以使用CTimeSpan类,具体使用方法如下: CTime t1( 1999, 3, 19, 22, 15, 0 ); CTime t = CTime::GetCurrentTime(); CTimeSpan span=t-t1; //计算当前系统时间与时间t1的间隔 int iDay=span.GetDays(); //获取这段时间间隔共有多少天 int iHour=span.GetTotalHours(); //获取总共有多少小时 int iMin=span.GetTotalMinutes();//获取总共有多少分钟 int iSec=span.GetTotalSeconds();//获取总共有多少秒c,获得当前日期和时间,并可以转化为CString CTime tm=CTime::GetCurrentTime(); CString str=tm.Format("%Y-%m-%d");//显示年月日 2.使用GetLocalTime:Windows API 函数,获取当地的当前系统日期和时间 (精确到毫秒) 此函数会把获取的系统时间信息存储到SYSTEMTIME结构体里边 typedef struct _SYSTEMTIME { WORD wYear;//年 WORD wMonth;//月 WORD wDayOfWeek;//星期:0为星期日,1为星期一,2为星期二…… WORD wDay;//日 WORD wHour;//时 WORD wMinute;//分 WORD wSecond;//秒 WORD wMilliseconds;//毫秒 }SYSTEMTIME,*PSYSTEMTIME;例: SYSTEMTIME st; CString strDate,strTime; GetLocalTime(&st); strDate.Format("%4d-%2d-%2d",st.wYear,st.wMonth,st.wDay); strTime.Format("%2d:%2d:%2d",st.wHour,st.wMinute,st.wSecond) ; AfxMessageBox(strDate); AfxMessageBox(strTime);3.使用GetTickCount:从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD。(精确到毫秒) //获取程序运行时间 long t1=GetTickCount();//程序段开始前取得系统运行时间(ms) Sleep(500); long t2=GetTickCount();();//程序段结束后取得系统运行时间(ms) str.Format("time:%dms",t2-t1);//前后之差即 程序运行时间 AfxMessageBox(str); //获取系统运行时间 long t=GetTickCount(); CString str,str1; str1.Format("系统已运行 %d时",t/3600000); str=str1; t%=3600000; str1.Format("%d分",t/60000); str+=str1; t%=60000; str1.Format("%d秒",t/1000); str+=str1; AfxMessageBox(str);4.使用time_t time( time_t * timer ) : 仅使用C标准库(精确到秒) 得到从标准计时点(一般是1970年1月1日午夜)到当前时间的秒数 计算时间差:double difftime( time_t timer1, time_t timer0) struct tm *localtime(const time_t *timer); 取得当地时间,localtime获取的结果由结构tm返回 返回的字符串可以依下列的格式而定: %a 星期几的缩写。Eg:Tue %A 星期几的全名。 Eg: Tuesday %b 月份名称的缩写。 %B 月份名称的全名。 %c 本地端日期时间较佳表示字符串。 %d 用数字表示本月的第几天 (范围为 00 至 31)。日期 %H 用 24 小时制数字表示小时数 (范围为 00 至 23)。 %I 用 12 小时制数字表示小时数 (范围为 01 至 12)。 %j 以数字表示当年度的第几天 (范围为 001 至 366)。 %m 月份的数字 (范围由 1 至 12)。 %M 分钟。 %p 以 ''AM'' 或 ''PM'' 表示本地端时间。 %S 秒数。 %U 数字表示为本年度的第几周,第一个星期由第一个周日开始。 %W 数字表示为本年度的第几周,第一个星期由第一个周一开始。 %w 用数字表示本周的第几天 ( 0 为周日)。 %x 不含时间的日期表示法。 %X 不含日期的时间表示法。 Eg: 15:26:30 %y 二位数字表示年份 (范围由 00 至 99)。 %Y 完整的年份数字表示,即四位数。 Eg:2008 %Z(%z) 时区或名称缩写。Eg:中国标准时间 %% % 字符。 含:年,月,日,周几,小时,分,秒,毫秒。[喝小酒的网摘]http://blog.const.net.cn/a/16370.htm
#include <time.h> tm localTM; memset(&localTM, 0, sizeof(localTM)); localTM.tm_year = 2016-1900; localTM.tm_mon = 4-1; localTM.tm_mday = 27; time_t localTime = mktime(&localTM); localTM.tm_mday = 29; time_t localTime2 = mktime(&localTM); double fTemp1 = difftime(localTime2, localTime); double fTemp2 = difftime(localTime, localTime2); double fTemp3 = difftime(localTime, localTime);
发表评论
-
FreeRTOS
2022-03-05 16:31 202Ref https://blog.csdn.net/weix ... -
串口通讯相关
2018-11-02 13:44 357https://bbs.csdn.net/wap/topics ... -
[转]C++验证IP是否可以PING通
2018-10-30 17:54 1221https://www.cnblogs.com/guoyz13 ... -
C++/MFC 換皮膚
2018-10-20 11:05 419https://blog.csdn.net/u01123991 ... -
WinCE 截屏 - C++ 代碼
2018-08-31 09:45 515// this function create a bmp ... -
Android NDK搭建環境
2017-11-27 13:25 525https://www.cnblogs.com/ut2016- ... -
8583协议相关
2017-10-17 13:38 5108583相关资料,整理中... -
Java高级应用之JNI
2017-06-19 09:00 536参考link http://www.cnblogs.com/l ... -
C++实现ping功能
2017-04-18 11:21 2021基础知识 ping的过程是向目的IP发送一个type=8的I ... -
OpenSSL 编译环境搭建
2017-03-27 15:01 8491 安裝VS2008到 c:\Program Files (x ... -
最优非对称加密填充(OAEP)
2017-03-25 14:53 1504OpenSSL命令---rsautl http://blog. ... -
[Platform Builder] 设置SVM OS build Env
2016-11-10 11:39 01 copy one OSDesign Project to ... -
[Windows] System Error Codes(GetLastError )0-----5999
2016-10-26 13:28 1831ERROR_SUCCESS 0 (0x0) T ... -
开源Windows驱动程序框架
2016-09-17 21:35 809转自 http://code.csdn.net/news/28 ... -
c/c++代码中执行cmd命令
2016-09-14 14:50 1808转自 http://blog.csdn.net/slixinx ... -
C#使用C++标准DLL实例(包含callback)
2016-09-11 19:44 996C++编写标准Win32DLL如下 头文件 /***** ... -
C#调用C++的DLL搜集整理的所有数据类型转换方式
2016-09-09 16:07 923转自 http://www.cnblogs.com/zeroo ... -
WinCE CPU使用率计算 测试工具
2016-09-08 16:14 931转自 http://blog.csdn.net/jan ... -
switch在C++与C#中的一些差异
2016-09-08 15:19 752参考链接 http://blog.csdn.net/weiwe ... -
C++ 鼠标模拟程序
2016-09-04 12:09 1526转自 http://blog.csdn.net/weixinh ...
相关推荐
获取系统的计数器的频率 BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount) 获取计数器的值 然后用两次计数器的差除以Frequency就得到时间。 7 Multimedia Timer Functions The following functions...
实现类似于C#上位机那种Log日志功能,即运行一次即可实现记录当前在何种时间做了何种动作,带...获取当前系统时间的各种数值,方便记录当前时间发生时间。三个输出可供选择,天、秒、毫秒、根据使用选择对应输出。
基于MFC调用系统时间,在edit box 上显示系统时间。仅仅实现显示功能。之后可以进行GPS时间的上传,都windows系统时间的校正 // TODO: Add extra initialization here CTime time = CTime::GetCurrentTime(); //...
快速获取目标网站服务器时间,让你在参加抢拍秒杀的时候,第一时间与网站同步。
获取系统时间和网络时间,其中系统时间我们只需要用now函数就可以得到,然后利用DateTimeToStr()函数将它转换为字符串格式赋值给Label1就行了。网络时间我们可以利用TidTime控件的DateTime属性直接得到,不过在使用...
里面有一个获取系统当前时间的方法,和一个获取两个时间间隔的方法
/* time - 获取计算机系统当前的日历时间(Calender Time) * 处理日期时间的函数都是以本函数的返回值为基础进行运算 * * 函数原型: * #include <time> * * time_t time(time_t *calptr); * * 返回
获取已开机时间。#include #include <time.h> #include #include void sleep( long wait ); void gettime(); void main( void ) { int flag=1; char time[128]; _strtime(time); printf( "OS time:%s\n",...
命令行工具TimeBack.exe获取和更改文件的创建、修改、访问时间 TimeBack 1.0 文件时间控制 作者:Xinje E-mail:xinje@126.com 2010.6.16 /F [文件名] 设置欲更改或查看文件时间的文件名。 /T [日期时间] 欲更改的...
本文实例讲述了C++获取当前系统时间的方法。分享给大家供大家参考。具体如下: 方案— 优点:仅使用C标准库;缺点:只能精确到秒级 #include <time> #include int main( void ) { time_t t = time(0); char tmp...
操作系统实验,压缩包中包括Linux和windows进程控制源代码及实验报告。 进程控制实验题目: 设计并实现Unix的“time”命令。...• 调用gettimeofday()来获取时间 mytime的用法: $ mytime.exe program1
新建一个winform工程,添加相应控件,将源码复制进去即可
Android 完美获取手机当前时区,解决时间偏移量和夏令时差问题.从本地时间里扣除这些变量,解决时间偏移量和夏令时差问题.从本地时间里扣除这些变量,
获取当前系统时间(VB源代码)
在C语言中可以使用time函数来获取系统时间,以下对time函数进行了介绍,需要的朋友可以过来参考下
获取Internet网络时间,自动同步并更新系统时间。 开发环境:VS2010
获取系统时间,能够正确显示当前北京时间。(年月日,分时秒)
#include<time.h> #include int main( ) { FILE *fp; fp = fopen("time.xls","a"); if(fp == NULL) { printf("can not open file.\n"); exit(0); } int year, month, day,hour,min,sec; char ch;...
获取实时时间的显示,年月日时分秒,运用到了线程,启动线程调用系统时间
但在这之前你需要了解一些“时间”和“日期”的概念,主要有以下几个: Coordinated Universal Time(UTC):协调世界时,又称为世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT)。...