FILETIMEをSYSTEMTIMEにへ変換します。
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <windows.h>
/*
FILETIMEをSYSTEMTIMEにへ変換する
*/
int _tmain
(
int argc
, _TCHAR* argv[]
)
{
// 標準出力にユニコード出力する
setlocale( LC_ALL, "Japanese" );
// ファイルのオープン
HANDLE hFile = ::CreateFile(
L"c:¥¥org¥¥test1.txt"
, 0
, 0
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
// オープン確認
if ( INVALID_HANDLE_VALUE != hFile ) {
FILETIME tCreationTime; // 作成日時
// ファイルの作成日時を取得する。
if ( 0== ::GetFileTime( hFile, &tCreationTime, NULL, NULL ) ) {
std::wcout << L"取得失敗しました。" << std::endl;
}
else {
SYSTEMTIME tSystemTime;
// FILETIMEをSYSTEMTIMEに変換する
::FileTimeToSystemTime( &tCreationTime, &tSystemTime );
const static TCHAR* wpaWeekName[] = {
L"日", L"月", L"火", L"水", L"木", L"金", L"土"
};
// 名称
wprintf( L"変換結果¥n" );
// SYSTEMTIME表示
wprintf( L"¥t%04d/%02d/%02d(%s) %02d:%02d:%02d.%03d¥n"
, tSystemTime.wYear
, tSystemTime.wMonth
, tSystemTime.wDay
, wpaWeekName[ tSystemTime.wDayOfWeek ]
, tSystemTime.wHour
, tSystemTime.wMinute
, tSystemTime.wSecond
, tSystemTime.wMilliseconds
);
}
// ファイルのクローズ
::CloseHandle( hFile );
}
// 正常終了
return( 0 );
}
変換結果
2013/01/24(木) 14:46:25.826