home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / PASTUT24.ZIP / PTUTRSRC.ZIP / TIMEDATE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-12-01  |  1.4 KB  |  43 lines

  1.                                      (* Chapter 14 - Program 8 *)
  2. program Get_Time_And_Date;
  3.  
  4. var Year,Month,Day     : integer;
  5.     Hour,Minute,Second : integer;
  6.  
  7. (*  The following procedure can be included in any MSDOS/PCDOS
  8.     program to get the present date and time. The present date
  9.     and time can then be printed on your output to automatically
  10.     time and date your output listings. Note that this is a TURBO
  11.     Pascal extension and will probably not work with other Pascal
  12.     compilers. This program uses some very advanced programming
  13.     techniques requiring knowledge of some of the details of the
  14.     DOS system. Don't worry if you don't understand all of this.
  15. *)
  16.  
  17. procedure Time_And_Date(var Year,Month,Day,Hour,Min,Sec : integer);
  18.  
  19. type Reg_Definitions = record
  20.        AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : integer;
  21.      end;
  22.  
  23. var Registers : Reg_Definitions;
  24.  
  25. begin
  26.    Registers.AX := $2A shl 8;   (* get todays date *)
  27.    Msdos(Registers);
  28.    Year  := Registers.CX;
  29.    Day   := Registers.DX mod 256;
  30.    Month := Registers.DX shr 8;
  31.  
  32.    Registers.AX := $2C shl 8;   (* get the time *)
  33.    Msdos(Registers);
  34.    Hour  := Registers.CX shr 8;
  35.    Min   := Registers.CX mod 256;
  36.    Sec   := Registers.DX shr 8;
  37. end;
  38.  
  39. begin
  40.    Time_And_Date(Year,Month,Day,Hour,Minute,Second);
  41.    Writeln('The date is ',Month:2,'/',Day:2,'/',Year);
  42.    Writeln('The time is ',Hour:2,':',Minute:2,':',Second:2);
  43. end.