原文地址:http://geeksforgeeks.org/getdate-and-setdate-function-in-c-with-examples
翻譯如下:更新于2019/07/24
getdate()
getdate() 函數(shù)定義在dos.h
頭文件中秉继。這個(gè)函數(shù)使用系統(tǒng)當(dāng)前的日期來填充*dt
這個(gè)date結(jié)構(gòu)體统台。
使用方法:
struct date dt;
getdate(&dt);
參數(shù): 該函數(shù)的參數(shù)只有一個(gè)date結(jié)構(gòu)體的指針蝠咆。
返回值: 無返回值康聂。只是獲取系統(tǒng)日期并將其填充到date
結(jié)構(gòu)體中贰健。
實(shí)例 1: getdate() 函數(shù)的實(shí)現(xiàn)
// 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() 函數(shù)定義在dos.h
頭文件中。這個(gè)函數(shù)通過*dt
這個(gè)date
結(jié)構(gòu)體來設(shè)置系統(tǒng)的日期恬汁。
使用方法
struct date dt;
setdate(&dt)
參數(shù): 傳入的參數(shù)是一個(gè)date
結(jié)構(gòu)體dt
伶椿,用來設(shè)置當(dāng)前的系統(tǒng)日期。
返回值: 無返回值蕊连。只是按照傳入的date
結(jié)構(gòu)體設(shè)置具體的系統(tǒng)日期悬垃。
實(shí)例 2: setdate() 的實(shí)現(xiàn)
// 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