当前位置: 首页 > news >正文

黄岐网站制作建立一个购物网站平台费用

黄岐网站制作,建立一个购物网站平台费用,ukidc做电影网站,管理软件的软件哪个好文章目录 前言一、几个时间相关的概念二、场景三、验证方法四、源码五、运行结果六、资源自取 前言 在应用中用到了 UTC 时间戳与北京时间进行转换的需求#xff0c;这里做一个记录#xff0c;方便后面有需求时直接拿来用。 一、几个时间相关的概念 GMT 时间#xff1a;Gr… 文章目录 前言一、几个时间相关的概念二、场景三、验证方法四、源码五、运行结果六、资源自取 前言 在应用中用到了 UTC 时间戳与北京时间进行转换的需求这里做一个记录方便后面有需求时直接拿来用。 一、几个时间相关的概念 GMT 时间Greenwich Mean Time格林尼治平时又称格林尼治平均时间或格林尼治标准时间。是指位于英国伦敦郊区的皇家格林尼治天文台的标准时间。 GMT存在较大误差因此现在已不再被作为标准时间使用。现在的标准时间是由原子钟报时的协调世界时UTC UTC 时间Universal Time Coordinated中文名称世界标准时间或世界协调时。 UTC时间可以理解为全世界都公用的一个时间。它实际上反映了一种约定即为全世界所认可的一个统一时间而不是某特定地区的时间。中国人常用的北京时间比 UTC 时间快8个小时。也即 UTC 时间凌晨 0 点时北京时间已经是早上 8 点这就是为啥全世界人往往不直接用 UTC 时间计时原因。 CST 时间China Standard Time即中国标准时间。在时区划分上属东八区比协调世界时早8小时记为UTC8。UNIX 时间戳timestamp计算机中的 UNIX 时间戳是以 GMT/UTC 时间 1970-01-01 00:00:00 为起点到当前具体时间的秒数不考虑闰秒。这样做的目的主要是通过“整数计算”来简化计算机对时间操作的复杂度。 二、场景 要求实现 UTC 时间戳和北京时间的互相转换其中月份取值范围为 0~11 代表 1~12月。其他时间参数正常年、日、时、分、秒 三、验证方法 可以使用 时间戳转换在线工具 来验证转换后的时间是否正确。 这里以 2023-10-30 18:42:00 这个时间为例转换后的 UTC 秒数为 1698662520。 四、源码 #include stdio.htypedef struct {int year; // 年份int month; // 月份范围0-11代表1-12月int day; // 日int hour; // 小时int minute; // 分钟int second; // 秒 } DateTime;int IsLeapYear(int year) {return (year % 4 0 year % 100 ! 0) || (year % 400 0); }int DaysInMonth(int year, int month) {int days[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };if (month 1 IsLeapYear(year))return 29;elsereturn days[month]; }int UTCSecondsToBeijing(DateTime* dt, int seconds) {int offset 8 * 3600; // 北京为东八区相对于UTC的偏移量为8小时int totalSeconds seconds offset;dt-year 1970;dt-month 0;dt-day 1;dt-hour 0;dt-minute 0;dt-second 0;while (totalSeconds 86400) {int daysInYear IsLeapYear(dt-year) ? 366 : 365;if (totalSeconds daysInYear * 86400) {totalSeconds - daysInYear * 86400;dt-year;}else {int month 0;while (totalSeconds DaysInMonth(dt-year, month) * 86400) {totalSeconds - DaysInMonth(dt-year, month) * 86400;month;}dt-month month;dt-day totalSeconds / 86400 1;totalSeconds % 86400;dt-hour totalSeconds / 3600;dt-minute (totalSeconds % 3600) / 60;dt-second totalSeconds % 60;break;}}return totalSeconds; }int BeijingTimeToUTCSeconds(const DateTime* dt) {int totalSeconds 0;for (int year 1970; year dt-year; year) {totalSeconds IsLeapYear(year) ? 366 * 86400 : 365 * 86400;}for (int month 0; month dt-month; month) {totalSeconds DaysInMonth(dt-year, month) * 86400;}totalSeconds (dt-day - 1) * 86400;totalSeconds dt-hour * 3600;totalSeconds dt-minute * 60;totalSeconds dt-second;int offset 8 * 3600; // 北京为东八区相对于UTC的偏移量为8小时totalSeconds - offset;return totalSeconds; }int main() {// 示例UTC秒数转换成北京时间int utcSeconds 1698662520; // 假设给定的UTC秒数DateTime beijingTime;int remainingSeconds UTCSecondsToBeijing(beijingTime, utcSeconds);printf(UTC Seconds: %d\n, utcSeconds);printf(Beijing Time: %04d-%02d-%02d %02d:%02d:%02d\n,beijingTime.year, beijingTime.month 1, beijingTime.day,beijingTime.hour, beijingTime.minute, beijingTime.second);printf(Remaining Seconds: %d\n\n, remainingSeconds);// 示例北京时间转换成UTC秒数DateTime inputTime;inputTime.year 2023;inputTime.month 12 - 1; // 月份范围0-11代表1-12月inputTime.day 30;inputTime.hour 18;inputTime.minute 42;inputTime.second 0;int utcSecondsResult BeijingTimeToUTCSeconds(inputTime);printf(Beijing Time: %04d-%02d-%02d %02d:%02d:%02d\n,inputTime.year, inputTime.month 1, inputTime.day,inputTime.hour, inputTime.minute, inputTime.second);printf(UTC Seconds: %d\n, utcSecondsResult);return 0; }上述代码分为两个部分一个是将 UTC 秒数转换为北京时间另一个是将北京时间转换为 UTC 秒数。你可以根据需要使用其中的任一部分。示例中的北京时间转换成 UTC 秒数部分使用的北京时间为 2023年10月30日18时42分 五、运行结果 从结果可以看到将 UTC 秒数转换成北京时间以及从北京时间转换成 UTC 秒数无误。 六、资源自取 UTC时间戳与北京时间转换 我的qq2442391036欢迎交流
http://www.pierceye.com/news/238263/

相关文章:

  • 如何用ps做网站图标吉林省长春市建设局网站
  • 北京高端网站建设服务广州百度快速排名优化
  • 电子商务网站开发课程设计网站建设石家庄
  • 好的公司网站有什么用烟台建设集团招聘信息网站
  • 网站制作需要多长时间网站代建设费用
  • 淘宝客网站设计台州建设银行官方网站
  • 婚纱网站建设规划书2023全国企业公司大黄页
  • 网站seo的关键词排名怎么做的wordpress 在线留言
  • 建一个c2c网站要多少钱小程序云开发文档
  • asp网站合法上虞网站设计
  • 网站 用什么数据库蛋糕店网站建设方案
  • 网站上的动效是用ae做的网站开发实训小结
  • wordpress建站怎么上传网站没有备案信息该怎么做
  • 沈阳网站推广有什么技巧软件开发工具通常也称为什么工具
  • 黑龙江龙采做网站如何网站建设制作解决方案
  • 百度推广自己做网站吗网页设计软件下载网站
  • wordpress内核源码分析南宁网站优化推广
  • 物流网站做那个好服务器怎么安装WordPress
  • 网站开发怎么兼容浏览器中国优秀设计网站有哪些内容
  • 黄冈网站官方登录平台做网站的条件
  • 潍坊网站建设推广公司网站建设类的手机软件
  • 建设小学网站建设网站代理
  • 怎么查看网站根目录网站建设费记什么科目
  • 文昌市规划建设管理局网站网站与个人网站
  • 昆明网站建设推荐q479185700上墙现在最火的推广平台有哪些
  • 长兴县城乡建设局网站wordpress的留言功能
  • 建设企业网站地址asp.net 4.0网站开...
  • 制作个人网站步骤提升学历励志语录
  • 福州建站服务管理页面布局标准格式
  • 做一个公司网站一般需要多少钱营销型网站功能表