13 out of 42 rated this helpful Rate this topic

FILETIME structure

Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

Syntax

typedef struct _FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
} FILETIME, *PFILETIME;

Members

dwLowDateTime

The low-order part of the file time.

dwHighDateTime

The high-order part of the file time.

Remarks

To convert a FILETIME structure into a time that is easy to display to a user, use the FileTimeToSystemTime function.

It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should copy the low- and high-order parts of the file time to a ULARGE_INTEGER structure, perform 64-bit arithmetic on the QuadPart member, and copy the LowPart and HighPart members into the FILETIME structure.

Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows.

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 NT FAT, 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 (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, the GetFileTime function may not return the same file time information set using the SetFileTime function. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC. For more information, see File Times.

A function using the FILETIME structure can allow for values outside of zero or positive values typically specified by the dwLowDateTime and dwHighDateTime members. For example, the SetFileTime function uses 0xFFFFFFFF to specify that a file's previous access time should be preserved. For more information, see the topic for the function you are calling.

Examples

For an example, see Changing a File Time to the Current Time or Retrieving the Last-Write Time.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

See also

File Times
CompareFileTime
FileTimeToSystemTime
GetFileTime
ULARGE_INTEGER

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
@chrisrus
It only says that *some* API's reserve special values that are not to be interpreted as 0 or positive time.
Structure ... can allow values of zero or positive values (#$#*^ --- WHAT!)
"A function using the FILETIME structure can allow for values outside of zero or positive values typically specified by the dwLowDateTime and dwHighDateTime members. " This sentence is devoid of informational content. What is this supposed to mean? I want to know if there are reserved FILETIME values, what their semantics are and which functions honor these semantics.
'FILETIME' in 'union'

Wouldn't this work (one or all of them)?:

union
{
FILETIME AsFileTime ;
ULARGE_INTEGER AsUlargeInteger ;
} MyFileTime ;


union
{
FILETIME AsFileTime ;
ULONGLONG AsULongLong ;
} MyFileTime ;
r

union
{
FILETIME AsFileTime ;
__Int64 AsInt64 ;
} MyFileTime ;


Why shouldn't I do arithmetics on the FileTime fields (members)?
Is it because a 'FILETIME' not embedded in an appropriate 'union'
is not surely 64-bitsaligned? I assume these unions will, am I wrong?

Best regards

Staffan Cronstrom


[A reply]
The most common reason would be that by doing such, you would probably also do it to a FILETIME in a structure when it is not 64 bit aligned. Having a union or a #pragma align(push/8/pop) argument around the structure definition should make it 64bit aligned, but it is not, by default, defined that way, and thus can be put on 32-bit boundaries.
Alternative to using unmanaged code

As an alternative to using this unmaged structure. As an alternative, you might consider using .NET's System.DateTime class, along wiht the ToFileTime and FromFileTime methods.

For more information on the class, see: http://msdn.microsoft.com/en-us/library/system.datetime_methods(VS.85).aspx. For information on the FromFileTime and ToFileTime methods, see: http://msdn.microsoft.com/en-us/library/system.datetime.fromfiletime(VS.85).aspx and http://msdn.microsoft.com/en-us/library/system.datetime.tofiletime(VS.85).aspx respectively.

C# syntax
[StructLayout(LayoutKind.Sequential)]
public struct FILETIME
{
public uint dwLowDateTime;
public uint dwHighDateTime;
}
vb.net syntax
<StructLayout(LayoutKind.Sequential)> Public Structure FILETIME
Public dwLowDateTime As UInt32
Public dwHighDateTime As UInt32
End Structure