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

企业网站的建设与实现论文整站优化系统厂家

企业网站的建设与实现论文,整站优化系统厂家,甜水园网站建设,网络广告类型一、介绍 在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/381228/

相关文章:

  • 顺义哪有做网站厂家百度快照在哪里找
  • 深圳南山网站建设重庆seo黄智
  • 教育微网站建设我要学电脑哪里有短期培训班
  • 民宿预订网站制作推广方案怎么做
  • 做网站都要掌握什么网页模版
  • 网站怎么做qq微信登陆长沙优化网站哪家公司好
  • 为什么上不了建设银行个人网站漳州网络推广
  • 天津手机网站建站培训代运营公司可靠吗
  • 网站制作的一般步骤长春网站优化平台
  • Python做网站 性能上海seo培训中心
  • 网上投诉平台公众号排名优化
  • 网页模板网站推荐媒体公关是做什么的
  • 泰安的网站建设公司爱站网域名查询
  • 台州椒江网站制作公司广告推销
  • 南康做网站合肥seo招聘
  • 成都网站建设定长沙专业网站制作
  • 有什么网站是python做的如何自己开发一个平台
  • 网站建设标志设计北京网站优化公司
  • 图标使用wordpress杭州seo博客
  • 企业网站如何做推广竞价推广托管公司介绍
  • 网站如何做微信登录seo公司 杭州
  • 中山里水网站建设软文广告案例分析
  • 做外贸是用什么网站做新型网络营销方式
  • 心理咨询网站开发百度手机seo软件
  • 17网站一起做网批seo营销优化
  • 做赚钱网站程序员培训班要多少钱
  • 已经收录大规模修改收录页面对网站有影响吗什么软件可以推广自己的产品
  • 丁香园做科室网站厦门网络推广
  • 免费的企业网站制作提高网站权重的方法
  • 兰州网站制作怎么样网页在线生成