utc 时间和北京时间的相互转换 获取系统时间戳

17 篇文章 0 订阅

http://eleaction01.spaces.eepw.com.cn/articles/article/item/208277

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

void utc_to_local2(char *dst ,const char *stamp)

{

//char buf[512];

long t = atoi(stamp);

struct tm x;

time_t cstamp = t;

x = *localtime(&cstamp);

sprintf(dst, "%d/%d/%d %d:%d:%d",x.tm_year+1900,x.tm_mon + 1, x.tm_mday, x.tm_hour, x.tm_min, x.tm_sec);

//printf("%s\n", dst);

}

/*获取系统时间戳*/

void get_stamp(void)

{

struct timeval t;

gettimeofday(&t,NULL);

printf("sec:%ld\n",t.tv_sec); // sec

printf("sec:%ld\n",t.tv_sec*1000+t.tv_usec); //msec

}

int main(void) {

char buf[64];

utc_to_local2(buf,"1677045422");

printf("%s\n", buf);

get_stamp();

return 0;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值