linux系统时间 time.h 之 asctime( ) 函数使用

/*
日历时间int类型tm结构体转字符串格式-asctime函数
char * asctime(const struct tm * time_ptr);
char * asctime_r(const struct tm * time_ptr,char* buf);
char * asctime_s(char * buf,rsize_t bufsz,const struct tm * time_ptr);

想要使用asctime_s函数必须在#include time.h头文件之前 #define __STDC_WANT_LIB_EXT1 1 
*/ 
//#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#include <stdio.h>
//#define __STDC_LIB_EXT1__ 
int main(void)
{
    struct tm tm = *localtime(&(time_t){time(NULL)});
    printf("%s", asctime(&tm));
 
#ifdef __STDC_LIB_EXT1__
    char str[26];
    asctime_s(str, sizeof str, &tm);
	//sizeof的大小低于26就不执行该函数吧 
	//将tm转化为字符串写入str 
    printf("%s", str);
#endif
}
//官方不建议使用 gmtime asctime ,建议使用strftime 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值