Partager via


CTime Class

Represents an absolute time and date.

class CTime

Members

Public Constructors

Name

Description

CTime::CTime

Constructs CTime objects in various ways.

Public Methods

Name

Description

CTime::Format

Converts a CTime object into a formatted string — based on the local time zone.

CTime::FormatGmt

Converts a CTime object into a formatted string — based on UTC.

CTime::GetAsDBTIMESTAMP

Converts the time information stored in the CTime object to a Win32-compatible DBTimeStamp structure.

CTime::GetAsSystemTime

Converts the time information stored in the CTime object to a Win32-compatible SYSTEMTIME structure.

CTime::GetCurrentTime

Creates a CTime object that represents the current time (static member function).

CTime::GetDay

Returns the day represent by the CTime object.

CTime::GetDayOfWeek

Returns the day of the week represented by the CTime object.

CTime::GetGmtTm

Breaks down a CTime object into components — based on UTC.

CTime::GetHour

Returns the hour represented by the CTime object.

CTime::GetLocalTm

Breaks down a CTime object into components — based on the local time zone.

CTime::GetMinute

Returns the minute represented by the CTime object.

CTime::GetMonth

Returns the month represented by the CTime object.

CTime::GetSecond

Returns the second represented by the CTime object.

CTime::GetTime

Returns a __time64_t value for the given CTime object.

CTime::GetYear

Returns the year represented by the CTime object.

CTime::Serialize64

Serializes data to or from an archive.

Operators

operator + –

These operators add and subtract CTimeSpan and CTime objects.

operator +=, –=

These operators add and subtract a CTimeSpan object to and from this CTime object.

operator =

The assignment operator.

operator ==, < , etc.

Comparison operators.

Remarks

CTime does not have a base class.

CTime values are based on coordinated universal time (UTC), which is equivalent to Coordinated Universal time (Greenwich Mean Time, GMT). See Time Management for information about how the time zone is determined.

When you create a CTime object, set the nDST parameter to 0 to indicate that standard time is in effect, or to a value larger than 0 to indicate that daylight saving time is in effect, or to a value less than zero to have the C run-time library code compute whether standard time or daylight saving time is in effect. tm_isdst is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. If timeptr points to a tm structure returned by a previous call to asctime_s, _gmtime_s, or localtime_s, the tm_isdst field contains the correct value.

A companion class, CTimeSpan, represents a time interval.

The CTime and CTimeSpan classes are not designed for derivation. Because there are no virtual functions, the size of CTime and CTimeSpan objects is exactly 8 bytes. Most member functions are inline.

Note

The upper date limit is 12/31/3000. The lower limit is 1/1/1970 12:00:00 AM GMT.

For more information about using CTime, see the articles Date and Time, and Time Management in the Run-Time Library Reference.

Note

The CTime structure changed from MFC 7.1 to MFC 8.0. If you serialize a CTime structure by using the operator << under MFC 8.0 or a later version, the resulting file will not be readable on older versions of MFC.

Requirements

Header: atltime.h

See Also

Reference

asctime_s, _wasctime_s

_ftime_s, _ftime32_s, _ftime64_s

gmtime_s, _gmtime32_s, _gmtime64_s

localtime_s, _localtime32_s, _localtime64_s

strftime, wcsftime, _strftime_l, _wcsftime_l

time, _time32, _time64

CTimeSpan Class

Hierarchy Chart

Other Resources

ATL/MFC Shared Classes