Using Date and Time Handling

Explains how to manipulate Date and Time.

Points in time are stored and manipulated using the TTime class. TTime uses a 64-bit integer to represent time as the number of microseconds since midnight on 1st January 0 AD, using a nominal Gregorian calendar. This gives a possible range of 580,000 years.

The date/time and its individual components may be set and retrieved using the TDateTime class. TDateTime is the human readable form of TTime. It is provided to allow easy user access to the year, month, day, hour, minute, second and microsecond components of the time. It does not support manipulation of the date/time, or of its components, but may be converted into a TTime, and vice versa.

Intervals between points in time are represented by the classes derived from TTimeIntervalBase and by class TTimeIntervalMicroSeconds. Time intervals can be added or subtracted, either to or from each other or to or from points in time. Time interval classes exist because adding two points in time or subtracting one point in time from another is not possible.

The Time class is a collection of time related utility functions; for example, functions that check for leap years and return the number of days in the month.

Arithmetic operations

Care should be taken when performing arithmetic operations on TTime s especially when dealing with the last day in the month. For example:

  • adding one month to October 18th adds 31 days

  • adding one month to November 18th adds 30 days

  • adding one year to February 29th, 1996 gives Feb 28th, 1997

  • adding one month to March 31st gives April 30th but subtracting one month from April 30th gives March 30th