C语言getdate函数、setdate函数的用法

原文地址: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  
#include  
  
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  
#include  
  
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

备注: 上述程序运行在TurboC/C++ compiler编译器下。

你可能感兴趣的:(C语言getdate函数、setdate函数的用法)