win32-FileTimeToSystemTime的使用

#include <Windows.h>
#include <iostream>
#include <string>
#pragma warning(disable:4996)

int main()
{    
    const char *day[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    const char* month[] = {"January","February","March","April","May","June","July", "August","September","October","November","December"};
    char day_[10];
    char month_[10];
    long long value = 132372033265000000; //文件时间
    FILETIME ft = { 0 };

    ft.dwHighDateTime = (value & 0xffffffff00000000) >> 32;
    ft.dwLowDateTime = value & 0xffffffff;

    SYSTEMTIME sys = { 0 };
    FileTimeToSystemTime(&ft, &sys);

    switch (sys.wDayOfWeek)
    {
        case 0:
            strcpy(day_, day[0]);
            break;
        case 1:
            strcpy(day_, day[1]);
            break;
        case 2:
            strcpy(day_, day[2]);
            break;
        case 3:
            strcpy(day_, day[3]);
            break;
        case 4:
            strcpy(day_, day[4]);
            break;
        case 5:
            strcpy(day_, day[5]);
            break;
        case 6:
            strcpy(day_, day[6]);
            break;
    }

    switch (sys.wMonth)
    {
    case 0:
        strcpy(month_, month[0]);
        break;
    case 1:
        strcpy(month_, month[1]);
        break;
    case 2:
        strcpy(month_, month[2]);
        break;
    case 3:
        strcpy(month_, month[3]);
        break;
    case 4:
        strcpy(month_, month[4]);
        break;
    case 5:
        strcpy(month_, month[5]);
        break;
    case 6:
        strcpy(month_, month[6]);
        break;
    }

    std::cout << day_ << "," << month_ << " " << sys.wDay << "," << sys.wYear << " "<< sys.wHour << ":" << sys.wMinute << ":" << sys.wSecond;

    return 0;
}

 

posted @ 2020-07-02 15:36  strive-sun  阅读(644)  评论(0编辑  收藏  举报