Help Center
Help Center›AfxNova›DateTime

CFileTime Class

Members (26)

CAST OperatorReturns the **CFileTime** value as a long integer.ConstructorsCreates a new **CFileTime** object initialized to the specified value.FormatConverts a **CFileTime** object to a string.GetAsFileTimeReturns the time as a **FILETIME** structure.GetAsSystemTimeReturns the time as a **SYSTEMTIME** structure.GetCurrentTimeReturns a **CFileTime** object that represents the current system date and time.GetTimeReturns the value of the **CFileTime** object.LET OperatorAssigns a value to a **CFileTime** object.LocalToUTCConverts a local file time to a file time based on the Coordinated Universal Time (UTC).OperatorsAdds, subtracts or compares **CFileTime** objects.SetTimeSets the date and time of this **CFileTime** object.UTCToLocalConverts time based on the Coordinated Universal Time (UTC) to local file time.CAST OperatorReturns the **CFileTimeSpan** value as a long integer.ConstructorsCreate new **CFileTimeSpan** objects initialized to the specified value.DateStringReturns the date as a string based on the specified mask, e.g. "dd-MM-yyyy".DayReturns the number of 100-nanosecond intervals that make up one day.GetTimeSpanReturns the value of the **CFileTimeSpan** object.HourReturns the number of 100-nanosecond intervals that make up one hour.LET OperatorAssigns a value to a **CFileTimeSpan** object.MillisecondReturns the number of 100-nanosecond intervals that make up one millisecond.MinuteReturns the number of 100-nanosecond intervals that make up one minute.OperatorsAdds, subtracts or compares **CFileTimeSpan** objects.SecondReturns the number of 100-nanosecond intervals that make up one second.SetTimeSpanSets the date and time of this **CFileTimeSpan** object.TimeStringReturns the time as a string based on the specified mask, e.g. "dd-MM-yyyy".WeekReturns the number of 100-nanosecond intervals that make up one week.

Documentation

CFileTime Class

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 in conjunction 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. A nanosecond is one-billionth of a second.

The following static const member variables are provided to simplify calculations (number of 100-nanosecond intervals):

CFileTime_Millisecond    10000ull
CFileTime_Second         CFileTime_Millisecond * 1000
CFileTime_Minute         CFileTime_Second * 60
CFileTime_Hour           CFileTime_Minute * 60
CFileTime_Day            CFileTime_Hour * 24
CFileTime_Week           CFileTime_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.

NameDescription
ConstructorsCreates a new CFileTime object initialized to the specified value.
CAST OperatorReturns the CFileTime value as a long integer.
LET OperatorAssigns a value to a CFileTime object.
OperatorsAdds, subtracts or compares CFileTime objects.
DateStringReturns the date as a string based on the specified mask, e.g. "dd-MM-yyyy".
DayReturns the number of 100-nanosecond intervals that make up one day.
FormatConverts a CFileTime object to a string.
GetAsFileTimeReturns the time as a FILETIME structure.
GetAsSystemTimeReturns the time as a SYSTEMTIME structure.
GetCurrentTimeReturns a CFileTime object that represents the current system date and time.
GetTimeReturns the value of the CFileTime object.
HourReturns the number of 100-nanosecond intervals that make up one hour.
LocalToUTCConverts a local file time to a file time based on the Coordinated Universal Time (UTC).
MillisecondReturns the number of 100-nanosecond intervals that make up one millisecond.
MinuteReturns the number of 100-nanosecond intervals that make up one minute.
SecondReturns the number of 100-nanosecond intervals that make up one second.
SetTimeSets the date and time of this CFileTime object.
TimeStringReturns the time as a string based on the specified mask, e.g. "dd-MM-yyyy".
UTCToLocalConverts time based on the Coordinated Universal Time (UTC) to local file time.
WeekReturns the number of 100-nanosecond intervals that make up one week.

CFileTimeSpan Class

This class provides methods for managing relative periods of time often encountered when performing operations concerning when a file was created, last accessed or last modified. The methods of this class are frequently used in conjunction with CFileTime class objects.

The CFileTimeSpan object can be created using an existing CFileTimeSpan object, or expressed as a 64-bit value. The default constructor sets the time span to 0.

NameDescription
ConstructorsCreate new CFileTimeSpan objects initialized to the specified value.
CAST OperatorReturns the CFileTimeSpan value as a long integer.
LET OperatorAssigns a value to a CFileTimeSpan object.
OperatorsAdds, subtracts or compares CFileTimeSpan objects.
DayReturns the number of 100-nanosecond intervals that make up one day.
GetTimeSpanReturns the value of the CFileTimeSpan object.
HourReturns the number of 100-nanosecond intervals that make up one hour.
MillisecondReturns the number of 100-nanosecond intervals that make up one millisecond.
MinuteReturns the number of 100-nanosecond intervals that make up one minute.
SecondReturns the number of 100-nanosecond intervals that make up one second.
SetTimeSpanSets the date and time of this CFileTimeSpan object.
WeekReturns the number of 100-nanosecond intervals that make up one week.

Constructors (CFileTime)

Create new CFileTime objects initialized to the specified value.

CONSTRUCTOR CFileTime
CONSTRUCTOR CFileTime (BYVAL nSpan AS ULONGLONG)
CONSTRUCTOR CFileTime (BYREF ft AS FILETIME)
CONSTRUCTOR CFileTime (BYREF st AS SYSTEMTIME)
ParameterDescription
nSpanA date and time expressed as a 64-bit value.
ftA FILETIME structure.
stA SYSTEMTIME structure.
Examples
DIM cft AS CFileTime = CFileTime().GetCurrentTime()
DIM cft AS CFileTime = AfxLocalFileTime
print cft.GetTime
DIM cft AS CFileTime = AfxLocalSystemTime
print cft.GetTime

Constructors (CFileTimeSpan)

Create new CFileTimeSpan objects initialized to the specified value.

CONSTRUCTOR CFileTimeSpan
CONSTRUCTOR CFileTimeSpan (BYVAL nSpan AS ULONGLONG)
CONSTRUCTOR CFileTimeSpan (BYREF cSpan AS CFileTimeSpan)
ParameterDescription
nSpanA period of time in milliseconds.
cSpanA CFileTimeSpan object.
Example
DIM cSpan AS CFileTimeSpan = CFileTime_Day

CAST Operator (CFileTime)

Returns the CFileTime value as a long integer.

OPERATOR CAST () AS LONGLONG
Examples
DIM cft AS CFileTime = CFileTime().GetCurrentTime()
DIM nTime AS LONGLONG = cft
print nTime
DIM cft AS CFileTime = CFileTime().GetCurrentTime()
DIM cft2 AS CFileTime = cft

CAST Operator (CFileTimeSpan)

Returns the CFileTimeSpan value as a long integer.

OPERATOR CAST () AS LONGLONG

LET Operator (=) (CFileTime)

Assigns a value to a CFileTime object.

OPERATOR LET (BYVAL nTime AS ULONGLONG)
OPERATOR LET (BYREF ft AS FILETIME)
OPERATOR LET (BYREF st AS SYSTEMTIME)
ParameterDescription
nTimeA date and time expressed as a 64-bit value.
ftA FILETIME structure.
stA SYSTEMTIME structure.
Examples
DIM cft AS CFileTime
cft = AfxLocalFileTime
print cft.GetTime
DIM cft AS CFileTime
cft = AfxLocalSystemTime
print cft.GetTime

LET Operator (=) (CFileTimeSpan)

Assigns a value to a CFileTimeSpan object.

OPERATOR LET (BYVAL nSpan AS LONGLONG)
OPERATOR LET (BYREF cSpan AS CFileTimeSpan)
ParameterDescription
nSpanA period of time in milliseconds.
cSpanA CFileTimeSpan object.

Operators (CFileTime)

Adds, subtracts or compares CFileTime objects.

OPERATOR + (BYREF dt AS CFileTime, BYREF dateSpan AS CFileTimeSpan) AS CFileTime
OPERATOR - (BYREF dt AS CFileTime, BYREF dateSpan AS CFileTimeSpan) AS CFileTime
OPERATOR - (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS CFileTimeSpan
OPERATOR += (BYREF dateSpan AS CFileTimeSpan)
OPERATOR -= (BYREF dateSpan AS CFileTimeSpan)
OPERATOR = (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN
OPERATOR <> (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN
OPERATOR < (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN
OPERATOR > (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN
OPERATOR <= (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN
OPERATOR >= (BYREF dt1 AS CFileTime, BYREF dt2 AS CFileTime) AS BOOLEAN

Operators (CFileTimeSpan)

Adds, subtracts or compares CFileTimeSpan objects.

OPERATOR + (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS CFileTimeSpan
OPERATOR - (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS CFileTimeSpan
OPERATOR += (BYREF dateSpan AS CFileTimeSpan)
OPERATOR -= (BYREF dateSpan AS CFileTimeSpan)
OPERATOR = (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN
OPERATOR <> (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN
OPERATOR < (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN
OPERATOR > (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN
OPERATOR <= (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN
OPERATOR >= (BYREF cSpan1 AS CFileTimeSpan, BYREF cSpan2 AS CFileTimeSpan) AS BOOLEAN

Day (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one day.

FUNCTION Day () AS ULONGLONG

Hour (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one hour.

FUNCTION Hour () AS ULONGLONG

Millisecond (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one millisecond.

FUNCTION Millisecond () AS ULONGLONG

Minute (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one minute.

FUNCTION Minute () AS ULONGLONG

Second (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one second.

FUNCTION Second () AS ULONGLONG

Week (CFileTime / CFileTimeSpan)

Returns the number of 100-nanosecond intervals that make up one week.

FUNCTION Week () AS ULONGLONG

DateString

Returns the date as a string based on the specified mask, e.g. "dd-MM-yyyy".

FUNCTION DateString (BYREF wszMask AS WSTRING, BYVAL lcid AS LCID = LOCALE_USER_DEFAULT) AS DWSTRING
ParameterDescription
wszMaskA picture string that is used to form the date.
The format types "d", and "y" must be lowercase and the letter "M" must be uppercase.
For example, to get the date string "Wed, Aug 31 94", the application uses the picture string "ddd',' MMM dd yy".
lcidOptional. The language identifier used for the conversion. Default is LOCALE_USER_DEFAULT.

The following table defines the format types used to represent days.

Format typeMeaning
dDay of the month as digits without leading zeros for single-digit days.
ddDay of the month as digits with leading zeros for single-digit days.
dddAbbreviated day of the week, for example, "Mon" in English (United States).
ddddDay of the week.

The following table defines the format types used to represent months.

Format typeMeaning
MMonth as digits without leading zeros for single-digit months.
MMMonth as digits with leading zeros for single-digit months.
MMMAbbreviated month, for example, "Nov" in English (United States).
MMMMMonth value, for example, "November" for English (United States), and "Noviembre" for Spanish (Spain).

The following table defines the format types used to represent years.

Format typeMeaning
yYear represented only by the last digit.
yyYear represented only by the last two digits. A leading zero is added for single-digit years.
yyyyYear represented by a full four or five digits, depending on the calendar used. Thai Buddhist and Korean calendars have five-digit years. The "yyyy" pattern shows five digits for these two calendars, and four digits for all other supported calendars. Calendars that have single-digit or two-digit years, such as for the Japanese Emperor era, are represented differently. A single-digit year is represented with a leading zero, for example, "03". A two-digit year is represented with two digits, for example, "13". No additional leading zeros are displayed.
yyyyyBehaves identically to "yyyy".
Return value

The formatted date.


TimeString

Returns the time as a string based on the specified mask, e.g. "hh':'mm':'ss".

FUNCTION TimeString (BYREF wszMask AS WSTRING, BYVAL lcid AS LCID = LOCALE_USER_DEFAULT) AS DWSTRING
ParameterDescription
ftA FILETIME structure.
wszMaskA picture string that is used to form the time.
lcidOptional. The language identifier used for the conversion. Default is LOCALE_USER_DEFAULT.

The application can use the following elements to construct a format picture string. If spaces are used to separate the elements in the format string, these spaces appear in the same location in the output string. The letters must be in uppercase or lowercase as shown, for example, "ss", not "SS". Characters in the format string that are enclosed in single quotation marks appear in the same location and unchanged in the output string.

PictureMeaning
hHours with no leading zero for single-digit hours; 12-hour clock
hhHours with leading zero for single-digit hours; 12-hour clock
HHours with no leading zero for single-digit hours; 24-hour clock
HHHours with leading zero for single-digit hours; 24-hour clock
mMinutes with no leading zero for single-digit minutes
mmMinutes with leading zero for single-digit minutes
sSeconds with no leading zero for single-digit seconds
ssSeconds with leading zero for single-digit seconds
tOne character time marker string, such as A or P
ttMulti-character time marker string, such as AM or PM
Return value

The formatted time.


Format (CFileTime)

Converts a CFileTime object to a string.

FUNCTION Format (BYREF wszFmt AS WSTRING) AS DWSTRING

Formatting codes:

CodeMeaning
%aAbbreviated weekday name
%AFull weekday name
%bAbbreviated month name
%BFull month name
%cDate and time representation appropriate for locale
%dDay of month as decimal number (01 – 31)
%HHour in 24-hour format (00 – 23)
%IHour in 12-hour format (01 – 12)
%jDay of year as decimal number (001 – 366)
%mMonth as decimal number (01 – 12)
%MMinute as decimal number (00 – 59)
%pCurrent locale's A.M./P.M. indicator for 12-hour clock
%SSecond as decimal number (00 – 59)
%UWeek of year as decimal number, with Sunday as first day of week (00 – 53)
%wWeekday as decimal number (0 – 6; Sunday is 0)
%WWeek of year as decimal number, with Monday as first day of week (00 – 53)
%xDate representation for current locale
%XTime representation for current locale
%yYear without century, as decimal number (00 – 99)
%YYear with century, as decimal number
%z, %ZEither the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%%Percent sign

The # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows.

  • %#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#%: # flag is ignored.
  • %#c: Long date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".
  • %#x* Long date representation, appropriate to current locale. For example: "Tuesday, March 14, 1995".
  • %#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y: Remove leading zeros (if any).
Remarks

Formats the value by using the format string which contains special formatting codes that are preceded by a percent sign (%).

Examples
print cft.Format("%A, %B %d, %Y %H:%M:%S")
DIM cft AS CFileTime
cft = AfxLocalFileTime
print cft.Format("%A, %B %d, %Y %H:%M:%S")

GetAsFileTime (CFileTime)

Returns the time as a FILETIME structure.

FUNCTION GetAsFileTime () AS FILETIME

GetAsSystemTime (CFileTime)

Returns the time as a SYSTEMTIME structure.

FUNCTION GetAsSystemTime () AS SYSTEMTIME

GetCurrentTime (CFileTime)

Returns a CFileTime object that represents the current system date and time.

FUNCTION GetCurrentTime () AS CFileTime

GetTime (CFileTime)

Returns the value of the CFileTime object.

FUNCTION GetTime () AS LONGLONG
Example
DIM cft AS CFileTime = CFileTime().GetCurrentTime()
print cft.GetTime

SetTime (CFileTime)

Sets the date and time of this CFileTime object

FUNCTION SetTime (BYVAL nTime AS ULONGLONG)
ParameterDescription
nTimeThe date and time expressed as a 64-bit value.

LocalToUTC (CFileTime)

Converts a local file time to a file time based on the Coordinated Universal Time (UTC).

FUNCTION LocalToUTC () AS CFileTime

UTCToLocal (CFileTime)

Converts time based on the Coordinated Universal Time (UTC) to local file time.

FUNCTION UTCToLocal () AS CFileTime

GetTimeSpan (CFileTimeSpan)

Returns the value of the CFileTimeSpan object.

FUNCTION GetTimeSpan () AS LONGLONG

SetTimeSpan (CFileTimeSpan)

Sets the date and time of this CFileTimeSpan object.

FUNCTION SetTimeSpan (BYVAL nSpan AS LONGLONG)
ParameterDescription
nSpanThe new value for the time span in milliseconds.