c语言如何获取当前日期和时间并全部转化成数字
发布网友
发布时间:2022-07-13 15:30
我来回答
共2个回答
热心网友
时间:2023-11-04 13:31
键盘输入用: scanf("%4d%2d%2d%2d%2d%2d", &year,&mo,&day,&h,&m,&s);
#include <stdio.h>
main(){
char str[]="20131014015835";
int year,mo,day,h,m,s;
// scanf("%4d%2d%2d%2d%2d%2d", &year,&mo,&day,&h,&m,&s);
sscanf(str,"%4d%2d%2d%2d%2d%2d", &year,&mo,&day,&h,&m,&s);
printf("%4d Nian\n%02d Yue\n%02d Ri\n%02d Shi\n%02d Fen\n%02d Miao\n",
year,mo,day,h,m,s);
}追问你没看清楚我的要求
热心网友
时间:2023-11-04 13:32
#include<time.h>
#include<stdio.h>
int main()
{
char buf[BUFSIZ];
time_t t = time(NULL);
struct tm* now = localtime(&t);
strftime(buf,BUFSIZ,"%Y%m%d%H%M%S",now);
puts(buf);
}