Sdílet prostřednictvím


COleDateTime Class

Encapsulates the DATE data type that is used in OLE automation.

class COleDateTime

Remarks

COleDateTime does not have a base class.

It is one of the possible types for the VARIANT data type of OLE automation. A COleDateTime value represents an absolute date and time value.

The DATE type is implemented as a floating-point value. Days are measured from December 30, 1899, at midnight. The following table shows some dates and their associated values:

Date

Value

December 29, 1899, midnight

-1.0

December 29, 1899, 6 A.M

-1.25

December 30, 1899, midnight

0.0

December 31, 1899, midnight

1.0

January 1, 1900, 6 A.M.

2.25

Poznámka

To determine the time, compute the absolute value of the fractional part of the number.

The COleDateTime class handles dates from January 1, 100, through December 31, 9999. The COleDateTime class uses the Gregorian calendar; it does not support Julian dates. COleDateTime ignores Daylight Saving Time. (See Date and Time: Automation Support.)

Poznámka

You can use the %y format to retrieve a two-digit year only for dates starting at 1900. If you use the %y format on a date before 1900, the code generates an ASSERT failure.

This type is also used to represent date-only or time-only values. By convention, the date 0 (December 30, 1899) is used for time-only values and the time 00:00 (midnight) is used for date-only values.

If you create a COleDateTime object by using a date less than 100, the date is accepted, but subsequent calls to GetYear, GetMonth, GetDay, GetHour, GetMinute, and GetSecond fail and return -1. Previously, you could use two-digit dates, but dates must be 100 or larger in MFC 4.2 and later.

To avoid problems, specify a four-digit date. For example:

COleDateTime mytime(1996, 1, 1, 0, 0, 0); 

Basic arithmetic operations for the COleDateTime values use the companion class COleDateTimeSpan. COleDateTimeSpan values define a time interval. The relationship between these classes is similar to the one between CTime and CTimeSpan.

For more information about the COleDateTime and COleDateTimeSpan classes, see the article Date and Time: Automation Support.

Requirements

**Header:**ATLComTime.h

See Also

Reference

COleVariant Class

CTime Class

CTimeSpan Class

Hierarchy Chart

Other Resources

COleDateTime Members

ATL/MFC Shared Classes