home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pascal2.zip / TIMEDATE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-01-15  |  1KB  |  42 lines

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