System time: Difference between revisions

→‎{{header|Pascal}}: substitute complicated TP [Turbo Pascal] solution by simple standardized EP [Extended Pascal] solution
(→‎{{header|Pascal}}: substitute complicated TP [Turbo Pascal] solution by simple standardized EP [Extended Pascal] solution)
Line 1,598:
 
=={{header|Pascal}}==
{{works with|TurboExtended Pascal|5.5}}
Extended Pascal, as defined by the ISO standard 10206, defines a <tt>record</tt> data type that at least identifies the following members:<lang Pascal>type
 
timeStamp = packed record
<lang Pascal>program systime;
dateValid: Boolean;
uses DOS;
year: integer;
 
month: 1..12;
{ Format digit with leading zero }
day: 1..31;
function lz(w: word): string;
timeValid: Boolean;
hour: 0..23;
minute: 0..59;
second: 0..59;
end;</lang>A variable of this built-in data type can be populated with the <tt>getTimeStamp</tt> procedure as demostrated below:<lang Pascal>program systemTime(output);
var
ts: timeStamp;
s: string;
begin
getTimeStamp(ts);
str(w,s);
if length(s) = 1 then
{
s := '0' + s;
If `getTimeStamp` is unable to obtain the time, it will
lz := s;
set `timeValid` to `false` and `hour`, `minute` and
end;
`second` are set to a time representing midnight (0:00:00).
 
}
var
if ts.timeValid then
h,m,s,c: word;
begin
yr,mo,da,dw: word;
writeLn(time(ts));
dt: datetime;
end;
t,ssm: longint;
regs: registers;
 
begin
 
{ Time and Date }
GetTime(h,m,s,c);
writeln(lz(h),':',lz(m),':',lz(s),'.',c);
GetDate(yr,mo,da,dw);
writeln(yr,'-',lz(mo),'-',lz(da));
 
{ Turbo Epoch, seconds }
with dt do begin
year := yr; month := mo; day := da;
hour := h; min := m; sec := s;
end;
packtime(dt,t);
writeln(t);
 
{ Seconds since midnight, PC-BIOS 1Ah }
regs.ah := 0; Intr($1A,regs);
ssm := round((regs.cx * 65536 + regs.dx) * (65536 / 1192180));
writeln(ssm);
 
end.</lang>
 
{{out}}
{{CURRENTTIME}}:42
23:42:35.9
The <tt>string</tt> representation generated by the standard function <tt>time</tt> is implementation-defined.
2010-07-29
The shown output was generated by a <tt>program</tt> compiled with the GPC, the GNU Pascal Compiler.
1023262033
A different processor might generate different output, for instance in an “AM”/“PM” format.
85427
 
=={{header|Perl}}==
149

edits