Muokkaa

Jaa


CFileTime class

This class provides methods for managing the date and time values associated with a file.

Syntax

class CFileTime :  public FILETIME

Members

Public constructors

Name Description
CFileTime::CFileTime The constructor.

Public methods

Name Description
CFileTime::GetCurrentTime Call this static function to retrieve a CFileTime object that represents the current system date and time.
CFileTime::GetTime Call this method to retrieve the time from the CFileTime object.
CFileTime::LocalToUTC Call this method to convert a local file time to a file time based on the Coordinated Universal Time (UTC).
CFileTime::SetTime Call this method to set the date and time stored by the CFileTime object.
CFileTime::UTCToLocal Call this method to convert time based on the Coordinated Universal Time (UTC) to local file time.

Public operators

Name Description
CFileTime::operator - This operator is used to perform subtraction on a CFileTime or CFileTimeSpan object.
CFileTime::operator != This operator compares two CFileTime objects for inequality.
CFileTime::operator + This operator is used to perform addition on a CFileTimeSpan object.
CFileTime::operator += This operator is used to perform addition on a CFileTimeSpan object and assign the result to the current object.
CFileTime::operator < This operator compares two CFileTime objects to determine the lesser.
CFileTime::operator <= This operator compares two CFileTime objects to determine equality or the lesser.
CFileTime::operator = The assignment operator.
CFileTime::operator -= This operator is used to perform subtraction on a CFileTimeSpan object and assign the result to the current object.
CFileTime::operator == This operator compares two CFileTime objects for equality.
CFileTime::operator > This operator compares two CFileTime objects to determine the larger.
CFileTime::operator >= This operator compares two CFileTime objects to determine equality or the larger.

Public constants

Name Description
CFileTime::Day A static data member storing the number of 100-nanosecond intervals that make up one day.
CFileTime::Hour A static data member storing the number of 100-nanosecond intervals that make up one hour.
CFileTime::Millisecond A static data member storing the number of 100-nanosecond intervals that make up one millisecond.
CFileTime::Minute A static data member storing the number of 100-nanosecond intervals that make up one minute.
CFileTime::Second A static data member storing the number of 100-nanosecond intervals that make up one second.
CFileTime::Week A static data member storing the number of 100-nanosecond intervals that make up one week.

Remarks

This class provides methods for managing the date and time values associated with the creation, access, and modification of files. The methods and data of this class are frequently used together with CFileTimeSpan objects, which deal with relative time values.

The date and time value is stored as a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. This format is the Coordinated Universal Time (UTC) format.

The following static const member variables are provided to simplify calculations:

Member variable Number of 100-nanosecond intervals
Millisecond 10,000
Second Millisecond * 1,000
Minute Second * 60
Hour Minute * 60
Day Hour * 24
Week Day * 7

Note

Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on the Windows NT FAT file system, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (the access date). On NTFS, access time has a resolution of 1 hour. Furthermore, FAT records times on disk in local time, but NTFS records times on disk in UTC. For more information, see File times.

Inheritance hierarchy

FILETIME
 └ CFileTime

Requirements

Header: atltime.h

CFileTime::CFileTime

The constructor.

CFileTime() throw();
CFileTime(const FILETIME& ft) throw();
CFileTime(ULONGLONG nTime) throw();

Parameters

ft
A FILETIME structure.

nTime
The date and time expressed as a 64-bit value.

Remarks

The CFileTime object can be created using an existing date and time from a FILETIME structure, or expressed as a 64-bit value (in local or Coordinated Universal Time (UTC) time formats). The default constructor sets the time to 0.

CFileTime::Day

A static data member storing the number of 100-nanosecond intervals that make up one day.

static const ULONGLONG Day = Hour* 24;

Example

See the example for CFileTime::Millisecond.

CFileTime::GetCurrentTime

Call this static function to retrieve a CFileTime object that represents the current system date and time.

static CFileTime GetCurrentTime() throw();

Return value

Returns the current system date and time in Coordinated Universal Time (UTC) format.

Example

// Retrieve the current time
CFileTime myFT;
myFT = CFileTime::GetCurrentTime();

CFileTime::GetTime

Call this method to retrieve the time from the CFileTime object.

ULONGLONG GetTime() const throw();

Return value

Returns the date and time as a 64-bit number, which may be in either local or Coordinated Universal Time (UTC) format.

CFileTime::Hour

A static data member storing the number of 100-nanosecond intervals that make up one hour.

static const ULONGLONG Hour = Minute* 60;

Example

See the example for CFileTime::Millisecond.

CFileTime::LocalToUTC

Call this method to convert a local file time to a file time based on the Coordinated Universal Time (UTC).

CFileTime LocalToUTC() const throw();

Return value

Returns a CFileTime object containing the time in UTC format.

Example

See the example for CFileTime::UTCToLocal.

CFileTime::Millisecond

A static data member storing the number of 100-nanosecond intervals that make up one millisecond.

static const ULONGLONG Millisecond = 10000;

Example

// Calculate the difference between two times
CFileTime myFT1, myFT2;
CFileTimeSpan myFTS;

// Get the first time
myFT1 = CFileTime::GetCurrentTime();

// Pause for a moment
UINT randVal;
rand_s(&randVal);
Sleep(randVal % 10000);

// Get the second time
myFT2 = CFileTime::GetCurrentTime();

// Calculate the time difference
myFTS = myFT2 - myFT1;

// Measure the difference
if (myFTS.GetTimeSpan() < CFileTime::Minute)
   printf_s("Less than a minute passed\n");
else
   printf_s("A minute or more passed\n");

if (myFTS.GetTimeSpan() < CFileTime::Second)
   printf_s("Less than a second passed\n");
else
   printf_s("A second or more passed\n");

if (myFTS.GetTimeSpan() < CFileTime::Millisecond)
   printf_s("Less than a millisecond passed\n");
else
   printf_s("A millisecond or more passed\n");

CFileTime::Minute

A static data member storing the number of 100-nanosecond intervals that make up one minute.

static const ULONGLONG Minute = Second* 60;

Example

See the example for CFileTime::Millisecond.

CFileTime::operator -

This operator is used to perform subtraction on a CFileTime or CFileTimeSpan object.

CFileTime operator-(CFileTimeSpan span) const throw();
CFileTimeSpan operator-(CFileTime ft) const throw();

Parameters

span
A CFileTimeSpan object.

ft
A CFileTime object.

Return value

Returns a CFileTime object or a CFileTimeSpan object representing the result of the time difference between the two objects.

CFileTime::operator !=

This operator compares two CFileTime objects for inequality.

bool operator!=(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to be compared.

Return value

Returns TRUE if the item being compared isn't equal to the CFileTime object, otherwise FALSE.

CFileTime::operator +

This operator is used to perform addition on a CFileTimeSpan object.

CFileTime operator+(CFileTimeSpan span) const throw();

Parameters

span
A CFileTimeSpan object.

Return value

Returns a CFileTime object representing the result of the original time plus a relative time.

CFileTime::operator +=

This operator is used to perform addition on a CFileTimeSpan object and assign the result to the current object.

CFileTime& operator+=(CFileTimeSpan span) throw();

Parameters

span
A CFileTimeSpan object.

Return value

Returns the updated CFileTime object, representing the result of the original time plus a relative time.

CFileTime::operator <

This operator compares two CFileTime objects to determine the lesser.

bool operator<(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to be compared.

Return value

Returns TRUE if the first object is less (earlier in time) than the second, FALSE otherwise.

Example

// Test for one time less than another
// Declare the CFileType objects
CFileTime myFT1, myFT2;

// Obtain the first time value
myFT1 = CFileTime::GetCurrentTime();

// Pause for a moment...
Sleep(1000);

// Obtain the second time value
myFT2 = CFileTime::GetCurrentTime();

// Perform the comparison
if (myFT1 < myFT2)
   _tprintf_s(_T("Time is going in the correct direction.\n"));
else
   _tprintf_s(_T("Oh dear. Time is going backwards.\n"));

CFileTime::operator <>=

This operator compares two CFileTime objects to determine equality or the lesser.

bool operator<=(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to be compared.

Return value

Returns TRUE if the first object is less than (earlier in time) or equal to the second, otherwise FALSE.

CFileTime::operator =

The assignment operator.

CFileTime& operator=(const FILETIME& ft) throw();

Parameters

ft
A CFileTime object containing the new time and date.

Return value

Returns the updated CFileTime object.

CFileTime::operator -=

This operator is used to perform subtraction on a CFileTimeSpan object and assign the result to the current object.

CFileTime& operator-=(CFileTimeSpan span) throw();

Parameters

span
A CFileTimeSpan object containing the relative time to subtract.

Return value

Returns the updated CFileTime object.

CFileTime::operator ==

This operator compares two CFileTime objects for equality.

bool operator==(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to compare.

Return value

Returns TRUE if the objects are equal, otherwise FALSE.

CFileTime::operator >

This operator compares two CFileTime objects to determine the larger.

bool operator>(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to be compared.

Return value

Returns TRUE if the first object is greater than (later in time) than the second, otherwise FALSE.

CFileTime::operator >=

This operator compares two CFileTime objects to determine equality or the larger.

bool operator>=(CFileTime ft) const throw();

Parameters

ft
The CFileTime object to be compared.

Return value

Returns TRUE if the first object is greater than (later in time) or equal to the second, otherwise FALSE.

CFileTime::Second

A static data member storing the number of 100-nanosecond intervals that make up one day.

static const ULONGLONG Second = Millisecond* 1000;

Example

See the example for CFileTime::Millisecond.

CFileTime::SetTime

Call this method to set the date and time stored by the CFileTime object.

void SetTime(ULONGLONG nTime) throw();

Parameters

nTime
The 64-bit value representing the date and time, in either local or Coordinated Universal Time (UTC) format.

CFileTime::UTCToLocal

Call this method to convert time based on the Coordinated Universal Time (UTC) to local file time.

CFileTime UTCToLocal() const throw();

Return value

Returns a CFileTime object containing the time in local file time format.

Example

// Convert a UTC time to local file time format
CFileTime myUTC_FT, myL_FT;
// Get system time (in UTC format)
myUTC_FT = CFileTime::GetCurrentTime();
// Convert to local file time
myL_FT = myUTC_FT.UTCToLocal();         

CFileTime::Week

A static data member storing the number of 100-nanosecond intervals that make up one week.

static const ULONGLONG Week = Day* 7;

Example

See the example for CFileTime::Millisecond.

See also

FILETIME
CFileTimeSpan class
Hierarchy chart
ATL/MFC shared classes