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

电商的网站怎么做的好网站站点的建立

电商的网站怎么做的好,网站站点的建立,专业网站设计网站,wordpress 短视频主题一、介绍 在C语言中,UTC(协调世界时)时间戳与北京时间(通常指中国标准时间,即东八区时间,UTC8)之间的转换,主要涉及到将UTC时间戳加上8小时的时差(忽略夏令时等复杂因素&…

一、介绍

  在C语言中,UTC(协调世界时)时间戳与北京时间(通常指中国标准时间,即东八区时间,UTC+8)之间的转换,主要涉及到将UTC时间戳加上8小时的时差(忽略夏令时等复杂因素)。
  首先,需要了解的是,时间戳是自1970年1月1日(UTC)以来的秒数。在C语言中,可以通过time()函数 或者 gettimeofday() 获取当前时间的UTC时间戳,然后可以通过添加相应的秒数来转换为北京时间。

二、示例

  下面是一个简单的示例代码,展示了如何将UTC时间戳转换为北京时间,并以YYYY-MM-DD HH:MM:SS的格式打印出来。为了简化示例,这里使用了gmtime(将时间戳转换为UTC时间)和 localtime(将时间戳转换为本地时间,这里假设本地时间是北京时间)来演示,但实际上,直接通过添加时差来转换更为直接和明确。

#include <stdio.h>  
#include <time.h>  #define BST (+1)
// 将UTC时间戳转换为北京时间并打印  
void print_beijing_time(time_t utc_timestamp) 
{  // 转换为北京时间(UTC+8)  time_t beijing_timestamp = utc_timestamp + 8 * 60 * 60; // UTC+8小时  printf("utc_timestamp= %ld\r\nbeijing_timestamp= %ld\r\n",utc_timestamp,beijing_timestamp);// 转换为本地时间结构体(这里假设本地时间是北京时间)  struct tm *beijing_time = localtime(&beijing_timestamp);  // 打印时间  printf("%04d-%02d-%02d %02d:%02d:%02d\n",  beijing_time->tm_year + 1900, // 年份从1900年开始  beijing_time->tm_mon + 1,     // 月份从0开始  beijing_time->tm_mday,        // 日  beijing_time->tm_hour,        // 小时  beijing_time->tm_min,         // 分钟  beijing_time->tm_sec);        // 秒  
}  int main(void)
{  struct tm *info;// 获取当前UTC时间戳  time_t now = time(NULL);  /* Get GMT time */info = gmtime(&now );printf("Current world clock:\n");printf("UTC :\r\n");printf("%04d-%02d-%02d %02d:%02d:%02d\n",  info->tm_year + 1900, // 年份从1900年开始  info->tm_mon + 1,     // 月份从0开始  info->tm_mday,        // 日  info->tm_hour,        // 小时  info->tm_min,         // 分钟  info->tm_sec);        // 秒  printf("London : %2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min);// 打印北京时间  print_beijing_time(now);  return 0;  
}

三、strftime函数的使用

在这里插入图片描述
  C 库 strftime() 函数用于将日期和时间格式化为字符串。它允许用户设置自定义的日期和时间表示。

size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) 

可以根据格式中定义并存储到 str 中的格式规则,格式化结构 timeptr 中表示的时间。
参数介绍


str − This is the pointer to the destination array where the resulting C string is copied.
maxsize − This is the maximum number of characters to be copied to str.
format − This is the C string containing any combination of regular characters and special format specifiers. These format specifiers are replaced by the function to the corresponding values to represent the time specified in tm. The format specifiers are −

在这里插入图片描述

timeptr − This is the pointer to a tm structure that contains a calendar time broken down into its components as shown below −

在这里插入图片描述
示例1:

#include <stdio.h>
#include <time.h>int main () {time_t rawtime;struct tm *info;char buffer[80];time( &rawtime );info = localtime( &rawtime );strftime(buffer,80,"%x - %I:%M%p", info);printf("Formatted date and time : |%s|\n", buffer );return(0);
}

效果:
在这里插入图片描述
示例2:

#include <stdio.h>
#include <time.h>
#define Size 50int main() {time_t t;struct tm *tmp;char MY_TIME[Size];// Get the current timetime(&t); // Convert to local timetmp = localtime(&t); // Format the date and timestrftime(MY_TIME, sizeof(MY_TIME), "%x - %I:%M%p", tmp);printf("Formatted date & time: %s\n", MY_TIME);return 0;
}

效果:
在这里插入图片描述
示例3:

#include<stdio.h>
#include<time.h>int main()
{time_t anytime;struct tm *current;char time_str[64];time(&anytime);current = localtime(&anytime);strftime(time_str, 64, "%A, %B %d, %Y", current);printf("Today is %s\n", time_str);return 0;
}

效果:
在这里插入图片描述

参考:
https://www.tutorialspoint.com/c_standard_library/c_function_strftime.htm

http://www.yayakq.cn/news/298886/

相关文章:

  • 国际交流中心网站建设与管理制度软件定制开发服务公司
  • 淮北市相山区建设局网站网站的发布方案有哪些
  • 班级的网站设计怎么做腾讯街景地图实景
  • 海珠建设网站网络黄页网址
  • ktv网站建设wordpress同步微博
  • 建站资源微博seo排名优化
  • 做视频网站怎么盈利模式沉默是金什么意思
  • 网站模板下载网站小米14系列发布会微博手机影像年
  • 企业电子商务网站建设教案从本地服务入手做本地网站
  • 网站变灰wordpress非凡主题里导航下拉菜单
  • 免费产品网站建设在线视频链接生成器
  • 设计网站特点wordpress换域名教程
  • 知乎怎么做自己网站推广产品网页模板下载好后怎么用
  • 企点qq售卖平台什么样的网站利于百度优化
  • 十大最好用虚拟机seo性能优化
  • 建行信用卡网站登录网站建设下一步计划
  • 网站排版设布局网站我们的客户
  • 电子商务网站开发步骤网页设计师考什么
  • 英文专业的网站建设一个虚拟主机空间挂两个网站
  • 手机免费网站空间国内做轮胎网站
  • 已经有网站了 怎么做app如何查询在建项目
  • 页面效果好的网站福利博客wordpress
  • 免费建站的方法流程宁波seo网络推广软件系统
  • 网站优化关键词怎么做自己怎么做电影网站吗
  • 如何自己设置网站中国宁波网手机首页
  • 官方网站app网页游戏平台哪个好
  • 微信网站登录网站建设怎么在图片上加字
  • 女孩做网站运营好吗传奇游戏开发
  • 简述如何对网站进行推广宁国网站建设|网站建设报价 - 新支点网站建设
  • 网站后台账户如何做会计分录档案网站建设比较分析