我能够获得当前日期,但输出结果类似于2010年9月1日,但我的要求是像"星期三"这样的当前日期不是像1这样的整数值.我的代码就在这里.
#include <dos.h>
#include <stdio.h>
#include<conio.h>
int main(void)
{
struct date d;
getdate(&d);
printf("The current year is: %d\n", d.da_year);
printf("The current day is: %d\n", d.da_day);
printf("The current month is: %d\n", d.da_mon);
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
请帮助我找到当天的星期日,星期一.........谢谢
你真的在为16位DOS写作,还是仅仅使用一些奇怪的过时教程?
strftime 可在任何现代C库中使用:
#include <time.h>
#include <stdio.h>
int main(void) {
char buffer[32];
struct tm *ts;
size_t last;
time_t timestamp = time(NULL);
ts = localtime(×tamp);
last = strftime(buffer, 32, "%A", ts);
buffer[last] = '\0';
printf("%s\n", buffer);
return 0;
}
Run Code Online (Sandbox Code Playgroud)