GetSystemTime(LPSYSTEMTIME lpSystemTime)
得到系统时间,这个时间是标准的UTC时间,也就是没有包含任何时区的时间的
GetLocalTime(LPSYSTEMTIME lpSystemTime)
得到当前时区的时间,它获取的是系统设置的地区的当地时间

FILETIME结构包含了文件或目录的日期和时间信息:(自1601年1月1日以来,单位为100纳秒)

typedef struct _FILETIME {

  DWORD dwLowDateTime; //低32位

  DWORD dwHighDateTime; //高32位

} FILETIME, *PFILETIME;

SYSTEMTIME结构包含了用户可识别的系统日期信息:

typedef struct _SYSTEMTIME {

    WORD wYear;//年

    WORD wMonth;//月

    WORD wDayOfWeek;//一周的第几天

    WORD wDay;//日

    WORD wHour;//小时

    WORD wMinute;//分

    WORD wSecond;//秒

    WORD wMilliseconds;//毫秒

} SYSTEMTIME, *PSYSTEMTIME;

=======================================================

函数FileTimeToSystemTime用来将文件时间格式转换为标准系统时间格式:

BOOL WINAPI FileTimeToSystemTime(

  __in   const FILETIME *lpFileTime, //文件时间

  __out  LPSYSTEMTIME lpSystemTime //系统时间

);

函数FileTimeToLocalTime用来将文件时间格式转换为本地文件时间:

 BOOL WINAPI FileTimeToLocalFileTime(
__in const FILETIME* lpFileTime,//文件时间
__out LPFILETIME lpLocalFileTime//本地文件时间
);

函数SystemTimeToFileTime则是将标准系统时间转换成文件时间格式:

BOOL WINAPI SystemTimeToFileTime(
__in const SYSTEMTIME *lpSystemTime,//系统时间
__out LPFILETIME lpFileTime//文件时间
);

函数SystemTimeToTzSpecificLocalTime是将标准系统时间转换为本地系统时间

BOOL WINAPI SystemTimeToTzSpecificLocalTime(
__in LPTIME_ZONE_INFORMATION lpTimeZone,//时区结构
__in LPSYSTEMTIME lpUniversalTime,//系统时间
__out LPSYSTEMTIME lpLocalTime//本地时间
);

=======================================================

GetSystemTime函数用来获得系统时间:

 void WINAPI GetSystemTime(
__out LPSYSTEMTIME lpSystemTime
);

 GetFileTime函数用来获得一个文件或目录的创建的时间、最后访问的时间以及最后修改的时间:

BOOL WINAPI GetFileTime(
__in HANDLE hFile, //文件或目录句柄
__out_opt LPFILETIME lpCreationTime, //返回的创建的日期和时间信息
__out_opt LPFILETIME lpLastAccessTime, //返回的最后访问的日期和时间信息
__out_opt LPFILETIME lpLastWriteTime //返回的最后修改的日期和时间信息 );

实例:

CString strPath("D:\\test.txt");
HANDLE hFile = CreateFile(strPath,
GENERIC_WRITE| GENERIC_READ, //必须有GENERIC_READ属性才能得到时间
FILE_SHARE_READ,
NULL,
TRUNCATE_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL); if (hFile != INVALID_HANDLE_VALUE)
{
SYSTEMTIME sysTime;
GetSystemTime(&sysTime);//这里得到的时间是标准系统时间,也就是0时区的时间。
GetLocalTime(&sysTime);//这里得到的是本地时间,也就是标准时间+时区时间 FILETIME fCreateTime, fAccessTime, fWriteTime; GetFileTime(&hFile, &fCreateTime, &fAccessTime, &fWriteTime);//获取文件时间 CString strTime; //将文件时间转换为本地系统时间的两种方式:
//(1)
FileTimeToLocalFileTime(&fCreateTime,&localTime);//将文件时间转换为本地文件时间
FileTimeToSystemTime(&localTime, &sysTime);//将文件时间转换为本地系统时间 //(2)
FileTimeToSystemTime(&fCreateTime, &sysTime);//将文件时间转换为标准系统时间
SystemTimeToTzSpecificLocalTime(&sysTime, &sysTime)//将标准系统时间转换为本地系统时间 strTime.Format(_T("%4d年%2d月%2d日,%2d:%2d:%2d"),
sysTime.wYear,
sysTime.wMonth,
sysTime.wDay,
sysTime.wHour,
sysTime.wMinute,
sysTime.wSecond
);
}

修文件创建时间,例子:

#include <Windows.h>
#include <stdio.h> bool ConvertFileTimeToLocalTime(const FILETIME *lpFileTime, SYSTEMTIME *lpSystemTime)
{
if (!lpFileTime || !lpSystemTime) {
return false;
}
FILETIME ftLocal;
FileTimeToLocalFileTime(lpFileTime, &ftLocal);
FileTimeToSystemTime(&ftLocal, lpSystemTime);
return true;
} bool ConvertLocalTimeToFileTime(const SYSTEMTIME *lpSystemTime, FILETIME *lpFileTime)
{
if (!lpSystemTime || !lpFileTime) {
return false;
} FILETIME ftLocal;
SystemTimeToFileTime(lpSystemTime, &ftLocal);
LocalFileTimeToFileTime(&ftLocal, lpFileTime);
return true;
} int main()
{
HANDLE hFile;
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stCreate, stAccess, stWrite;
int year, month, day; hFile = CreateFile(L"C:\\1.txt", GENERIC_READ | GENERIC_WRITE, , NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (INVALID_HANDLE_VALUE == hFile) {
printf("CreateFile error: %d", GetLastError());
ExitProcess();
}
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
ConvertFileTimeToLocalTime(&ftCreate, &stCreate);
ConvertFileTimeToLocalTime(&ftAccess, &stAccess);
ConvertFileTimeToLocalTime(&ftWrite, &stWrite); printf("yyyy-MM-dd:");
scanf("%d-%d-%d", &year, &month, &day);
stAccess.wYear = stWrite.wYear = year;
stAccess.wMonth = stWrite.wMonth = month;
stAccess.wDay = stWrite.wDay = day; ConvertLocalTimeToFileTime(&stAccess, &ftAccess);
ConvertLocalTimeToFileTime(&stWrite, &ftWrite); SetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
CloseHandle(hFile);
return ;
}

WINDOWS API ——GETFILETIME——获取文件时间的更多相关文章

  1. Windows API教程文件系统

    本篇文章主要介绍了"Windows API教程文件系统",主要涉及到Windows API教程文件系统方面的内容,对于Windows API教程文件系统感兴趣的同学可以参考一下. ...

  2. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  3. 在VBA中使用Windows API

    VBA是一种强大的编程语言,可用于自定义Microsoft Office解决方案.通过使用VBA处理一个或多个Office应用程序对象模型,可以容易地修改Office应用程序的功能或者能够使两个或多个 ...

  4. WinSpy涉及的windows api

    WinSpy涉及的windows api WinSpy是仿造微软Spy++的开源项目,但只涉及Spy++的窗口句柄.窗口的属性.styles.类名子窗口.进程线程信息等查找功能.功能虽然不算强大,但涉 ...

  5. Windows API Finishing

    input { font-size: 14px; height: 26px } td { border-style: none; border-color: inherit; border-width ...

  6. Windows API函数大全(完整)

    Windows API函数大全,从事软件开发的朋友可以参考下 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一 ...

  7. Windows API Hook

    原文地址:http://blog.sina.com.cn/s/blog_628821950100xmuc.html 原文对我的帮助极大,正是由于看了原文.我才学会了HOOK.鉴于原文的排版不是非常好, ...

  8. [windows菜鸟]Windows API函数大全(完整)

    Windows API函数大全,从事软件开发的朋友可以参考下 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一 ...

  9. WINDOWS API 大全(一)

    1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...

随机推荐

  1. HDU 1010 Tempter of the Bone (DFS+可行性奇偶剪枝)

    <题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...

  2. POJ_2376_Cleaning Shifts【贪心】【区间覆盖】

    题目链接 题目大意: 有一些奶牛,每只奶牛负责一个时间段.问覆盖完全部的时间段最少需要多少只奶牛.若不能全部覆盖,输出-1. #include <cstdio>#include <a ...

  3. python专题 --- 递归

    如果一个函数在函数内部调用自身本身,这个函数就是递归函数 举例如阶乘函数,其数学递归定义如下: 对应的算法实现 def fact(n): if n==1: return 1 return n * fa ...

  4. java设计模式之-观察者模式(发布-订阅模式)

    1.观察者模式定义  观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象. 这个主题对象在状态上发生变化时,会通知所有观察者对象,让它们能够自动更新自己. 2.观察者模式结构 ...

  5. 李宏毅机器学习笔记6:Why deep、Semi-supervised

    李宏毅老师的机器学习课程和吴恩达老师的机器学习课程都是都是ML和DL非常好的入门资料,在YouTube.网易云课堂.B站都能观看到相应的课程视频,接下来这一系列的博客我都将记录老师上课的笔记以及自己对 ...

  6. Django 学习第六天——Django模型基础第一节

    一.Django 的 ORM 简介: Django的ORM系统的分析: 1.ORM 概念:对象关系映射(Object Relational Mapping,简称ORM) 2.ORM的优势:不用直接编写 ...

  7. 2108 ACM 向量积 凹凸

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2108 图一中,向量a × 向量 b    根据右手定则,得出向量c的方向.即为凸多边形. 图二中,若向量a ...

  8. [USACO18JAN]Stamp Painting

    Description: Bessie想拿\(M\) 种颜色的长为\(K\) 的图章涂一个长为\(N\) 的迷之画布.假设他选择涂一段区间,则这段区间长度必须为\(K\) ,且涂完后该区间颜色全变成图 ...

  9. BZOJ2240 : ural1676 Mortal Combat

    首先如果最大匹配不足$n$个那么显然每条边都不可能在匹配为$n$的方案中. 对于一条边$(u,v)$,如果它可能在最大匹配中,有两种情况: $1.(u,v)$是当前方案的匹配边. $2.$可以沿着$( ...

  10. BKDR Hash 函数实现

    K&R一书中提出的BKDR Hash算法,这里给出C函数实现,实际用的时候分布比较好而且实现简单.唯一不明白的就是为什么选择131这种模式的数字作为种子,隐隐有沃尔夫勒姆31号自动机的似曾相识 ...