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|
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
dateValid: Boolean;
year: integer;
month: 1..12;
day: 1..31;
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;
begin
getTimeStamp(ts);
{
If `getTimeStamp` is unable to obtain the time, it will
set `timeValid` to `false` and `hour`, `minute` and
end;▼
`second` are set to a time representing midnight (0:00:00).
}
if ts.timeValid then
begin▼
writeLn(time(ts));
▲ end;
▲begin
end.</lang>
{{out}}
{{CURRENTTIME}}:42
The <tt>string</tt> representation generated by the standard function <tt>time</tt> is implementation-defined.
The shown output was generated by a <tt>program</tt> compiled with the GPC, the GNU Pascal Compiler.
A different processor might generate different output, for instance in an “AM”/“PM” format.
=={{header|Perl}}==
|