windows 使用GetLocalTime()和GetSystemTime()所获得的时间不同

51 篇文章 1 订阅
[cpp]  view plain  copy
  1. #include <iostream.h>  
  2. //#include <winbase.h>  
  3. #include <windows.h>  
  4. //#pragma comment(lib,"kernel32.lib")  
  5. //using namespace std;  
  6. void main()  
  7. {  
  8. SYSTEMTIME systime;  
  9. GetLocalTime(&systime);//本地时间  
  10. cout<<"今天是:";  
  11.     cout<<systime.wYear<<"年"<<systime.wMonth<<"月"<<systime.wDay<<"日"<<endl;  
  12. cout<<"现在时间是:";  
  13. cout<<systime.wHour<<":"<<systime.wMinute<<":"<<systime.wSecond<<":"<<systime.wMilliseconds<<endl;  
  14. cout<<"星期"<<systime.wDayOfWeek<<endl;  
  15. cout<<endl;  
  16. GetSystemTime(&systime);//系统时间  
  17. cout<<"现在时间是:";  
  18. cout<<systime.wHour<<":"<<systime.wMinute<<":"<<systime.wSecond<<":"<<systime.wMilliseconds<<endl;  
  19. cout<<endl;  
  20. }   
  21.   
  22. GetSystemTime:所返回的是UTC.   
  23.   
  24. 协调世界时(Coordinated Universal Time,简写作UTC,之前也被拼做Universal Time Coordinated,有时是Universal Coordinated Time)是由国际无线电咨询委员会定义和建议采用的,并由国际时间局(BIH)负责保持的以国际单位制(SI)秒为单位的时间标度。对与无线电规则相关的大部分实际应用而言,协调世界时(UTC)与本初子午线(经度零度)上的平均太阳时等效。该时间过去以格林威治平均时(GMT)表示。     
  25.   
  26. 协调世界时使用24小时制的时钟表示,但也可以被转换为12小时制的时钟(AM和PM)。UTC用于飞行和航海,它有时也被称作祖鲁。UTC使用阳历   
  27.   
  28. --------------------------------   
  29.   
  30. GetLocalTime:返回的是本地时间,我建议一般用这个时间来作为你使用的时间   
  31.   
  32. void getsystemtime(   
  33. lpsystemtime lpsystemtime // system time   
  34. );   
  35. void getlocaltime(   
  36. lpsystemtime lpsystemtime // system time   
  37. );   
  38. typedef struct _systemtime {   
  39. word wyear;   
  40. word wmonth;   
  41. word wdayofweek;   
  42. word wday;   
  43. word whour;   
  44. word wminute;   
  45. word wsecond;   
  46. word wmilliseconds;   
  47. } systemtime, *psystemtime;  
  48.   
  49.   
  50. SYSTEMTIME systm;   
  51. GetSystemTime(&systm);  
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值