ARTICLE AD BOX
I am reading the WPD_OBJECT_DATE_MODIFIED time value of a file/folder on a Portable Device (WPD) and need to display it similar to how Explorer does. I have a folder whose Date Modified is displayed in Explorer as 1/1/2015 12:00AM.
I need to get the same formatted string. In my application, the following code kind of works, but the values are off as below:
SYSTEMTIME systemTime = { 0 }; FILETIME fileTime = { 0 }; FILETIME localFileTime = { 0 }; PROPVARIANT pvDateModified; PropVariantInit(&pvDateModified); //... HRESULT hrDateModified = pObjectProperties->GetValue(WPD_OBJECT_DATE_MODIFIED, &pvDateModified); if (pvDateModified.vt != VT_EMPTY) { // (0) Comes back as Variant Time: // RESULT: // pvDateModified.date = 42005.000000000 // (1) Need to convert to System Time first: // RESULT: // wYear=2015 // wMonth=1 // wDay=1 VariantTimeToSystemTime(pvDateModified.date, &systemTime); // (3) In order to use SHDateFormatTime, need to convert to File Time: // RESULT: // dwLowDateTime = 3803807744 // dwHighDateTime = 30418261 SystemTimeToFileTime(&systemTime, &fileTime); // (4) Format using SHFormatDateTime: // RESULT: // 12/31/2014 7:00 PM wchar_t datebuf[80]; DWORD flags = FDTF_NOAUTOREADINGORDER | FDTF_DEFAULT; // tried with and without, no difference SHFormatDateTime(&fileTime, &flags, datebuf, 80); //... }The result is incorrect by 5 hours, 12/31/2014 7:00 PM. Then I tried going further and getting Local Time, and it set me back even further, to 12/31/2014 2:00 PM:
// (4) Convert to Local Time First: // RESULT: // dwLowDateTime = 4192434176 // dwHighDateTime = 30418219 FileTimeToLocalFileTime(&fileTime, &localFileTime); // (5) Format using SHFormatDateTime: // RESULT: // 12/31/2014 2:00 PM wchar_t datebuf[80]; DWORD flags = FDTF_NOAUTOREADINGORDER | FDTF_DEFAULT; // tried with and without, no difference SHFormatDateTime(&localFileTime, &flags, datebuf, 80); //...I can see in the debugger that the original System Time systemTime is correct: 1/1/2015. But I can't use that time for the formatted string call SHFormatDateTime, it only takes a FILETIME rather than a SYSTEMTIME. But somewhere in the conversion from SYSTEMTIME to FILETIME there's an issue.
