*/
Want to see what people are talking about? See the latest forum posts.
*/

View \TIMEDATE.PAS

This is the second disk of the PASCAL TUTOR system. It has the

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


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.

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.