博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows中获取和设置系统日期时间的C程序
阅读量:2531 次
发布时间:2019-05-11

本文共 2144 字,大约阅读时间需要 7 分钟。

In this C program, we have to set, get the system’s date and time.

在此C程序中,我们必须设置,获取系统的日期和时间。

To get, set the system’s date and time, we need to include ‘dos.h’ header file.

要获取,设置系统的日期和时间,我们需要包含“ dos.h”头文件。

Here are the structure and function which are using in the program (all are declared in dos.h header file),

这是程序中使用的结构和功能(所有都在dos.h头文件中声明),

1) struct dosdate_t

1)结构dosdate_t

It is a predefined structure which is used for date, time related operations, it has following members,

它是一种预定义的结构,用于与日期,时间相关的操作,具有以下成员,

struct dosdate_t {
unsigned char day; /* 1--31 */ unsigned char month; /* 1--12 */ unsigned int year; /* 1980--2099 */ unsigned char dayofweek; /* 0--6; 0 = Sunday */};

2) _dos_getdate(&date);

2)_dos_getdate(&date);

It is used to get the current system date and time, assigns it to the ‘date’, which is a variable of ‘dosdate_t’ structure.

它用于获取当前系统日期和时间,并将其分配给“ date”,这是“ dosdate_t”结构的变量。

3) _dos_setdate(&date);

3)_dos_setdate(&date);

It is used to set the current system date or/and time, date or/and must be assigned in ‘date’ structure.

它用于设置当前系统日期或/和时间,日期或/,并且必须在“日期”结构中分配。

程序获取,在C中设置系统的日期和时间 (Program to get, set the system’s date and time in C)

</ s> </ s> </ s>
/*    * program to get and set the current system date in windows    * Compiler : turboC*/ #include 
#include
int main(){
char choice; struct dosdate_t date; /*predefine structure to get date*/ _dos_getdate(&date); printf("\nCurrent date is : %02d -%02d -%02d",date.day,date.month,date.year); printf("\nWant to change date (Y: yes):"); choice=getchar(); if(choice=='Y'||choice=='y'){
printf("Enter new date :\n"); printf("Enter day :"); scanf("%d",&date.day); printf("Enter month:"); scanf("%d",&date.month); printf("Enter year :"); scanf("%d",&date.year); _dos_setdate(&date); printf("\nDate changed successfully."); } return 0;}

Output

输出量

Current date is : 04 -07 -2012    Want to change date (Y: yes):Y    Enter new date :    Enter day  :10    Enter month:7    Enter year :2012    Date changed successfully.

翻译自:

转载地址:http://uuxzd.baihongyu.com/

你可能感兴趣的文章
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
为啥程序会有bug?
查看>>
跨域技术
查看>>
JS里的居民们7-对象和数组转换
查看>>
计算两个日期的时间间隔,返回的是时间间隔的日期差的绝对值.
查看>>
python初体验
查看>>
配置vue,vue脚手架的应用(老版本)
查看>>
linux下防火墙iptables原理及使用
查看>>
经典C面试真题精讲
查看>>
Remove Duplicates from Sorted List解题报告
查看>>
ffmpeg格式转换命令
查看>>
万方数据知识平台 TFHpple +Xpath解析
查看>>
Hive实现oracle的Minus函数
查看>>
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>
RocketMQ配置
查看>>
vs code调试console程序报错--preLaunchTask“build”
查看>>