原文地址:http://geeksforgeeks.org/getdate-and-setdate-function-in-c-with-examples
翻译如下:更新于2019/07/24
getdate()
getdate() 函数定义在dos.h
头文件中。这个函数使用系统当前的日期来填充*dt
这个date结构体。
使用方法:
struct date dt;
getdate(&dt);
参数: 该函数的参数只有一个date结构体的指针。
返回值: 无返回值。只是获取系统日期并将其填充到date
结构体中。
实例 1: getdate() 函数的实现
// C program to demonstrate getdate() method
#include <dos.h>
#include <stdio.h>
int main()
{
struct date dt;
// This function is used to get
// system's current date
getdate(&dt);
printf("System's current date\n");
printf("%d/%d/%d",
dt.da_day,
dt.da_mon,
dt.da_year);
return 0;
}
输出:
System's current date
18/4/2019
setdate()
getdate() 函数定义在dos.h
头文件中。这个函数通过*dt
这个date
结构体来设置系统的日期。
使用方法
struct date dt;
setdate(&dt)
参数: 传入的参数是一个date
结构体dt
,用来设置当前的系统日期。
返回值: 无返回值。只是按照传入的date
结构体设置具体的系统日期。
实例 2: setdate() 的实现
// C program to demonstrate setdate() method
#include <dos.h>
#include <stdio.h>
int main()
{
struct date dt;
// This function is used to get
// system's current date
getdate(&dt);
printf("System's current date\n");
printf("%d/%d/%d",
dt.da_day,
dt.da_mon,
dt.da_year);
printf("Enter date in the format (date month year)\n");
scanf("%d%d%d", &dt.da_day, &dt.da_mon, &dt.da_year);
// This function is used to change
// system's current date
setdate(&dt);
printf("System's new date (dd/mm/yyyy)\n")
printf("%d%d%d", dt.da_day, dt.da_mon, dt.da_year);
return 0;
}
输出:
System's current date
18/4/2019
Enter date in the format (date month year)
20 4 2018
System's new date (dd/mm/yyy)
20/4/2018