Set and Get the System Time

26. Program to set and get the system time?

Program


#include<dos.h>
#include<conio.h>
#include<stdio.h>
void main()
{
 union REGS in,out;
 int hr,min,sec;
 clrscr();
/*----Getting the System Time----*/
 in.h.ah=0X2C;
 int86(0X21,&in,&out);
 printf("\nCURRENT SYSTEM TIME: %d: %d: %d",out.h.ch,out.h.cl,out.h.dh);
/*----Setting the System Time----*/
 printf("\nENTER NEW TIME:");
 printf("\nHOURS:");
 scanf("%d",&hr);
 in.h.ch=hr;
 printf("\nMINUTE:");
 scanf("%d",&min);
 in.h.cl=min;
 printf("\nSECONDS:");
 scanf("%d",&sec);
 in.h.dh=sec;
 in.h.ah=0X2D;
 int86(0X21,&in,&out);
 printf("\nNEW SYSTEM TIME: %d: %d: %d",out.h.ch,out.h.cl,out.h.dh);
 getch();
}

Output

CURRENT SYSTEM TIME: 15: 56: 17                                                
ENTER NEW TIME:                                                                
HOURS:3                                                                        
                                                                               
MINUTE:15                                                                       
                                                                               
SECONDS:20                                                                     
                                                                                
NEW SYSTEM TIME: 3: 15: 20 

No comments:

Post a Comment