getdate() 函数定义在 time.h 头文件中。此函数有助于将字符串指向的给定日期/时间规范转换为结构体 'tm' 或分解时间。
struct tm *getdate(const char *string); #where string is representation of a date or time
getdate() 函数接受一个参数,即指向日期/时间表示的字符串指针。结构体 tm 分配在静态存储中,它将被后续的 getdate() 函数调用覆盖。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 字符串 | 指向缓冲区的指针(日期或时间的表示) | 必需 |
该函数将日期/时间的字符串表示形式转换为分解时间并存储在 tm 结构中。指向此结构体的指针将作为函数输出返回。为了返回错误值,此函数使用外部变量或宏 getdate_err。
| 输入 | 返回值 |
|---|---|
| 如果参数 | 指向此结构体的指针 |
#include <stdio.h>
#include <time.h>
int main()
{
struct date datm;
getdate(&datm;);
printf("Current system's date:\n");
printf("%d/%d/%d",
datm.da_day,
datm.da_mon,
datm.da_year);
return 0;
}
输出
Current system's date: 18/4/2019
#include <stdio.h>
#include <time.h>
int main (){
struct date dt;
getdate(&dt;);
printf("Operating system's current date is %d-%d-%d\n"
,dt.da_day,dt.da_mon,dt.da_year);
return 0;
}
输出
Operating system’s current date is 12-01-2012