【C语言:获取系统时间显示或存入数组中】

【C语言:获取系统时间显示或存入数组中】,第1张

【C语言:获取系统时间显示或存入数组中】

C语言:获取系统时间显示或存入数组中?

把系统时间存入数组中显示系统时间

把系统时间存入数组中
#include
#include 
 
 
int main()
{
	//获取系统时间并把时间存到数组中
	time_t  t;
	char  buf[128];
	memset(buf,0,sizeof(buf));
	struct tm *tmp;
	t = time(NULL);
	tmp = localtime(&t);
	strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tmp);
        
        return 0;
}
显示系统时间
#include
#include 
#include
 
int main()
{
    time_t t;
    struct tm * st;
    time (&t);//获取系统时间
    st = localtime (&t);
    printf ( "%d/%d/%d %d:%d:%dn",st->tm_year+1900, st->tm_mon, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec);//输出结果
 
    return 0;
}

					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5702560.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存