わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

FILETIMEをSYSTEMTIMEにへ変換する

FILETIMEをSYSTEMTIMEにへ変換します。

FILETIMEをSYSTEMTIMEにへ変換する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#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






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。