TURBO PASCAL

Новости

Программы   

Turbo Pascal 

Игры

Документация   

Странности

FAQ

Ссылки

Форум

Гостевая книга

Рассылка

Благодарности

Об авторе

57: How can I calculate the difference between two points of time?

 A: This is an unconfirmed answer so be a little careful with it.
But at the very least it shows some interesting information about
Turbo Pascal date/time conventions and how to declare and initialize
typed constants if they are records.
  program TimDifTest;
  uses Dos;
  const a : DateTime
          = (year:1992; month:10; day:24; hour:5; min:29; sec:38);
        b : DateTime
          = (year:1993; month:11; day:23; hour:6; min:30; sec:51);
  var aLong, bLong, cLong : longint;
      c : DateTime;
  begin
    PackTime (a, aLong);
    PackTime (b, bLong);
    cLong := bLong - aLong;
    UnpackTime (cLong, c);
    writeln (c.year-1980, ' ', c.month, ' ', c.day, ' ',
              c.hour, ' ', c.min, ' ', c.sec);
  end.
More generally than for dates between 1980 and 2079, or for more
accurate results, the difference between two date/times can be
calculated using Zeller's congruence (see the item "I want code that
gives the weekday of the given date"). First calculate Zeller's for
both the dates, convert them, and the hour, min, and sec into
seconds, subtract, and convert back.

 Contents

На первую страницу

Rambler's Top100 Rambler's Top100
PROext: Top 1000

(с)Все права защищены

По всем интересующим вопросам прошу писать на электронный адрес

Hosted by uCoz