如何利用C语言来获取当地时间和UTC时间? (设当地时间是北京时间)
发布日期:2021-07-28 20:33:31 浏览次数:2 分类:技术文章

本文共 1304 字,大约阅读时间需要 4 分钟。

#include  
#include
int main(){ time_t t = time(NULL); tm *tp = localtime(&t); // 北京时间 printf("%d/%d/%d\n", tp->tm_mon+1, tp->tm_mday, tp->tm_year + 1900); printf("%d:%d:%d\n", tp->tm_hour, tp->tm_min, tp->tm_sec); return 0;}

 

#include  
#include
int main(){ time_t t = time(NULL); // UTC秒数 tm *tp = localtime(&t); // 北京时间 printf("%d/%d/%d\n", tp->tm_mon+1, tp->tm_mday, tp->tm_year + 1900); printf("%d:%d:%d\n", tp->tm_hour, tp->tm_min, tp->tm_sec); // UTC今天秒数 int second1 = t % (24 * 60 * 60); printf("%d\n", second1); // 北京时间今天秒数 int second2 = tp->tm_hour * 3600 + tp->tm_min * 60 + tp->tm_sec; printf("%d\n", second2); // UTC时间与北京时间相隔的小时数 printf("%d\n", (second1 - second2) / 3600); // -8 return 0;}

 

#include  
#include
#include
int main(int argc, char* argv[]){ SYSTEMTIME stCurTime = {0}; GetSystemTime(&stCurTime); // UTC时间 printf("%d/%d/%d\n", stCurTime.wMonth, stCurTime.wDay, stCurTime.wYear); printf("%d:%d:%d\n", stCurTime.wHour, stCurTime.wMinute, stCurTime.wSecond); printf("----------\n"); GetLocalTime(&stCurTime); // 北京时间 printf("%d/%d/%d\n", stCurTime.wMonth, stCurTime.wDay, stCurTime.wYear); printf("%d:%d:%d\n", stCurTime.wHour, stCurTime.wMinute, stCurTime.wSecond); return 0;}

 

转载地址:https://blog.csdn.net/stpeace/article/details/13169089 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:strtok在分割字符串中的重要用途
下一篇:利用sprintf和sscanf实现十六进制和十进制之间的相互转换

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年03月23日 10时24分15秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

c语言中如何将字符串的元素一个一个取出_C语言中常用的字符串操作函数 2019-04-21
2d游戏地图编辑器_王者荣耀:新版本爆料!地图编辑器“天工”即将开测,游戏怎么玩由你定!... 2019-04-21
.net framework服务启动后停止_dos命令net图文教程,start启动系统服务stop停止服务批处理脚本... 2019-04-21
8k分辨率需要多大带宽_超乎想象!用RTX3080显卡连索尼8K电视玩游戏感受如何?... 2019-04-21
win10怎么开启aptx_Win10未来的黑科技?微软SurfaceFleet大曝光 2019-04-21
creo视图管理器使用方法_学以致用之中望3D—浅谈使用中望3D的初步感受 2019-04-21
周育如的音标口诀大全_花鸟画口诀大全,实用! 2019-04-21
心电图计算心率公式_医学常用的计算公式口诀(内外妇儿),赶快收藏! 2019-04-21
select 移动端 第一个无法选中_Python爬虫微博(移动端)评论 2019-04-21
华为云welink成像是反的_华为发布智能办公神器WeLink,可连接会议室开会,还可一键遥控报销和智能翻译... 2019-04-21
唱好铁血丹心谐音正规_趙贤典:打好“感情牌” 唱好“大合唱” 2019-04-21
aix系统vi修改命令_Linux基础知识必备:利用vi编辑器创建和编辑正文文件 2019-04-21
天涯明月刀开发_玩家被天涯明月刀手游“冷落”?六大门派角色竟不带正眼看人... 2019-04-21
this指向undefined uiapp_一个this都没有,真好 2019-04-21
add p4 多个文件_2-3【微信小程序全栈开发课程】index页面完善--vue文件代码解析... 2019-04-21
5w2h原则指的是什么_什么是5W2H分析法?一首小诗带入进入大门。 2019-04-21
技校毕业是什么学历_中等职业学校是什么_中等职业学校毕业是什么学历 2019-04-21
2压缩备份数据库_MySQL数据备份与恢复(二) xtrabackup工具 2019-04-21
英特尔cpu发布时间表_被嘲讽的英特尔核显,强大能力其实超乎你的想象 2019-04-21
chi2inv函数 matlab_MATLAB概率和统计(2) 2019-04-21