Category : Pascal Source Code
Archive   : PASTUT.ZIP
Filename : TIMEDATE.PAS

 
Output of file : TIMEDATE.PAS contained in archive : PASTUT.ZIP
(* Chapter 14 - Program 8 *)
program Get_Time_And_Date;

var Year,Month,Day : integer;
Hour,Minute,Second : integer;

(* The following procedure can be included in any MSDOS/PCDOS
program to get the present date and time. The present date
and time can then be printed on your output to automatically
time and date your output listings. Note that this is a TURBO
Pascal extension and will probably not work with other Pascal
compilers. This program uses some very advanced programming
techniques requiring knowledge of some of the details of the
DOS system. Don't worry if you don't understand all of this.
*)

procedure Time_And_Date(var Year,Month,Day,Hour,Min,Sec : integer);

type Reg_Definitions = record
AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : integer;
end;

var Registers : Reg_Definitions;

begin
Registers.AX := $2A shl 8; (* get todays date *)
Msdos(Registers);
Year := Registers.CX;
Day := Registers.DX mod 256;
Month := Registers.DX shr 8;

Registers.AX := $2C shl 8; (* get the time *)
Msdos(Registers);
Hour := Registers.CX shr 8;
Min := Registers.CX mod 256;
Sec := Registers.DX shr 8;
end;

begin
Time_And_Date(Year,Month,Day,Hour,Minute,Second);
Writeln('The date is ',Month:2,'/',Day:2,'/',Year);
Writeln('The time is ',Hour:2,':',Minute:2,':',Second:2);
end.

  3 Responses to “Category : Pascal Source Code
Archive   : PASTUT.ZIP
Filename : TIMEDATE.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/