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.

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

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

程序获取,在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 <stdio.h>
#include <dos.h>
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.

翻译自: https://www.includehelp.com/c-programs/c-program-get-set-system-date-time.aspx

Windows中获取和设置系统日期时间的C程序相关推荐

  1. Android 系统(194)---Android实践 -- 设置系统日期时间和时区

    Android实践 -- 设置系统日期时间和时区 转自:https://www.cnblogs.com/Free-Thinker/p/6627813.html 设置系统日期时间和时区 设置系统的日期时 ...

  2. 如何在Python中获取文件创建和修改日期/时间?

    我有一个脚本,该脚本需要根据文件创建和修改日期执行一些操作,但必须在Linux和Windows上运行. 在Python中获取文件创建和修改日期/时间的最佳跨平台方法是什么? #1楼 最好的功能是os. ...

  3. linux-shell命令之date【显示/设置系统日期/时间】

    功能说明:显示或设置系统时间与日期. 语法介绍:date [-d <字符串>][-u][+%H%I%K%l%M%P%r%s%S%T%X%Z%a%A%b%B%c%d%D%j%m%U%w%x% ...

  4. C#设置系统日期时间格式

     当开发时某些软件具有特定的日期格式,需要设置系统日期格式,保证软件正常运行. DllImport需要using System.Runtime.InteropServices; [DllImport( ...

  5. 【转载】Delphi获取与设置系统时间格式(长日期与短日期)

    Delphi获得与设置系统时间格式 在Delphi中,特别是在写管理系统软件时,经常要用到 FormatDateTime 以将 TDateTime 格式的日期时间转换成字符串形式的值显示或保存起来,或 ...

  6. executequery方法_【接口测试】soapui中数字、字符串、日期时间、数据库连接参数化的设置方法...

    先回顾下前几篇soapui工具操作文章: 在soapui里面使用groovy脚本生成测试报告的方法 在soapui里面用groovy传递cookie身份信息的方法 soapui中进行接口响应数据的关联 ...

  7. date-打印或者设置系统日期和时间

    date:打印或者设置系统日期和时间. 语法: date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss ...

  8. vba更改计算机系统时间,如何设置系统日期,一行VBA编程代码教你学会

    No.1 VBA编程中,获取日期是一个简单的功能,同样对日期进行增减计算处理也是个容易的操作. 本节我们来了解一下关于计算机系统日期的一些操作. DateAdd函数 如上图所示,DateAdd是一个函 ...

  9. wincc显示系统时间_wincc系统日期时间获取

    wincc 系统日期时间获取 系统时间的获得,有两种办法,一是建立 TAG ,二是使用函数获取 系统时间 方法一: 在 [Tag Management] 添加新的驱动 "System Inf ...

最新文章

  1. Zabbix安装(十):监控windows进程
  2. Maven的安装与Eclipse的配置
  3. Visual Studio中的Build和Rebuild区别
  4. Python初学的几个迷惑点
  5. 高薪寻人 | 2018 “神策杯”高校算法大师赛 6 强诞生,【招人】进行时……
  6. linux exchange邮件客户端,Linux中使用Hiri邮件客户端访问Exchange帐户
  7. 六.dbms_session(提供了使用PL/SQL实现ALTER SESSION命令)
  8. 微型计算机最怕的是什么,为什么以前学生上“微机课”都要穿鞋套?老师:怕电脑中病毒...
  9. 私有静态方法private static method-值得用吗?
  10. angular访问后台服务及监控会话超时的封装实现
  11. poj 3422 (费用流)
  12. evolving checkers players [Fogel and Chellapilla, 2002]
  13. python超市管理系统总汇总功能解说_控制台超市系统(Python)
  14. 微信小程序: 摇色子
  15. 项目的运筹帷幄—项目进度、质量和成本最优决策理论探讨
  16. 基本医疗保险如何看门诊
  17. druid监控页面 关闭_druid-springboot-starter默认启用监控页面,公网项目可能外泄DB信息...
  18. openresty ngx_lua常用指令
  19. 微信小程序开发知识点
  20. 代理模式相关简单论述

热门文章

  1. 2021计算机基础知识题库,2021~2021计算机基础知识练习题
  2. protobuf版本常见问题
  3. strict=False 但还是size mismatch for []: copying a param with shape [] from checkpoint,the shape in cur
  4. oracle死锁优化,Oracle性能优化之LockContention(转)
  5. java请假审批怎么实现_java实现请假时间判断
  6. 不规则图形数格子的方法_【微课堂】人教版五年级数学(上)6.5不规则图形的面积图文精讲+教学视频+同步练习...
  7. buck电路上下管_推荐 | 学好电路设计与仿真?你不能错过这两本书籍 ~
  8. 提出离职后怎么定last day_不管你因为什么离职,用正规的离职方式是你最正确的选择!...
  9. atomikosdatasourcebean mysql_SpringBoot2整合JTA组件实现多数据源事务管理
  10. html中的异步请求数据格式,解决layui中table异步数据请求不支持自定义返回数据格式的问题...