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

博罗做网站报价seo营销方法

博罗做网站报价,seo营销方法,网站smtp服务器,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.hkea.cn/news/755895/

相关文章:

  • 网站自动采集指标sem广告投放是做什么的
  • 想做一个个人网站怎么做培训学校
  • 网站开发ipv6升级如何创建自己的小程序
  • 做网站需要备案吗外贸网站推广与优化
  • 独立网站建设流程b站视频推广网站动漫
  • 泰安诚信的网站建设b站推广入口2023年
  • 高校网站建设资料库东莞seo推广公司
  • 电子印章手机在线制作软件四川seo整站优化费用
  • 个人风采网站制作外贸网站平台哪个好
  • 沈阳企业建站谷歌推广和seo
  • .la域名做的网站如何快速推广app
  • 广州优化网站建设怎么用手机制作网站
  • 做微网站的第三方学网络营销
  • 湖南做网站的公司有哪些搜索引擎是什么
  • flash网站管理系统seo优化排名易下拉用法
  • 永年网站建设友链互换平台推荐
  • 企业网站的设计公司网络广告营销的典型案例
  • 高校思政主题网站建设的意义关键词歌词任然
  • 哪里做网站比较快2345网址导航下载桌面
  • 广州建设委员会官方网站凡科建站下载
  • 全球做网站的公司排名百度一下你就知道官网
  • 小企业网站价格免费发链接的网站
  • 买了空间和域名 怎么做网站哪家公司网站做得好
  • 网站备案是否关闭衡阳网站建设公司
  • 遂昌建设局网站个人怎么做网站
  • 软件开发和网站建设网络营销的未来6个发展趋势
  • 做网站一年多少钱免费seo网站推广
  • 智通人才网东莞最新招聘信息官网seo是如何做优化的
  • 个人做跨境电商网站百度地图导航手机版免费下载
  • 阿里云注册网站之后怎么做网站百度联盟是什么