Hi Wayde,
I am sorry if I have any offence.
Since I have also tried the Windows API that get the file timestamp which
will give the localtime on win9x.
The Windows APIs do not define *any* file time behavior; they only provides
access to the file times as exposed by individual file systems.
BOOL GetLastWriteTime(HANDLE hFile, LPTSTR lpszString)
{
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC;
// Retrieve the file times for the file.
if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
return FALSE;
// Convert the last-write time to local time.
FileTimeToSystemTime(&ftWrite, &stUTC);
//SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
cout<<stUTC.wHour<<endl<<stUTC.wMinute<<endl;
// Build a string showing the date and time.
sprintf(lpszString, "%02d/%02d/%d %02d:%02d",
stUTC.wMonth, stUTC.wDay, stUTC.wYear,
stUTC.wHour, stUTC.wMinute);
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile;
hFile = CreateFile(TEXT("C:\\test.txt"), // file to create
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
OPEN_EXISTING, // overwrite existing
FILE_ATTRIBUTE_NORMAL | // normal file
FILE_FLAG_OVERLAPPED, // asynchronous I/O
NULL);
char str[1024];
GetLastWriteTime(hFile,str);
cout<<str<<endl;
return 0;
}
Microsoft only defines 2 file systems: FAT and NTFS. However, it is very
possible that a developer might encounter other 3rd party file systems,
especially when using non-Windows servers. So you may need to be very
careful about what time stamp dependencies they design into their
applications.
Since my test is all based on NTFS or FAT, because the Win9x did not use
NTFS due to its design, we only test it on FAT.
So if you are using a total different FS, e.g. you are reading a file on a
third party file systems. So I think the file behavior, is almost always
file system specific. Here I assume you are testing on win9x, which is
working on FAT filesystem and the test file is also on the FAT FS.
If I have any misunderstanding, please feel free to post here.
I understand that it is hard to replace all the win9x system with NT ones,
but as we state before, it is rarely that the Win9x will change its
timezone frequently. Also based on my test, if we create a file share which
pointed to a foder on a NTFS FS, the GetLastWriteTimeUtc will return the
same UTC time.
If you still have any concern, please feel free to post here.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.