获取时间

 

#include <stdio.h>
#include <time.h>

struct tm *get_time(void)
{
	time_t t;
  
	time(&t);
	t += 8*60*60;				// 加时区
	struct tm *tm = localtime(&t);

	tm->tm_year += 1900;
	tm->tm_mon += 1;
	
	return tm;
}

int main(void)
{
    struct tm *tm = get_time();
 
    printf("%4d年%02d月%02d日 %02d:%02d:%02d\n",
        tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
    
    return 0;
}

 

运行结果:

  

C 库函数 – localtime() | 菜鸟教程 (runoob.com) 

C语言应用(1)——Unix时间戳和北京时间的相互转换 (eepw.com.cn)

 

posted @ 2023-03-20 13:59  迷人的危险~  阅读(24)  评论(0)    收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css