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. RESTful架构&简单使用Django rest framework

    RESTful架构 1 什么是REST REST全称是Representational State Transfer,中文意思是表述性状态转移. 它首次出现在2000年Roy Fielding的博士论 ...

  2. 003.Ceph扩展集群

    一 基础准备 参考<002.Ceph安装部署>文档部署一个基础集群. 二 扩展集群 2.1 扩展架构 需求:添加Ceph元数据服务器node1.然后添加Ceph Monitor和Ceph ...

  3. 大数据技术 - 通俗理解MapReduce之WordCount(三)

    上一章我们编写了简单的 MapReduce 程序,掌握这些就能编写大多数数据处理的代码.但是 MapReduce 框架提供给用户的能力并不止如此,本章我们仍然以上一章 word count 为例,继续 ...

  4. CSS-选择器权重计算

    权重计算规则 内联样式,如: style=" ",权值为1000. ID选择器,如:#content,权值为0100. 类,伪类和属性选择器,如.content,权值为0010. ...

  5. windows系统 webstorm安装zencoding方法

    今天在webstorm安装zencoding,下载地址:http://code.google.com/p/zen-coding/downloads/list,下载以下文件: WebIDE and In ...

  6. 说说我安装pyspider遇到的那些坑

    现在python3.7  >>pip install pyspider    配置环境变量 前置的phantomjs 无界面浏览器,设置就不说了 cmd 中运行pyspider all  ...

  7. python 列表常用操作(二)

    1.tuple 的 unpack a,b = t 2.格式化输出 print('您的输入:{},值为{}',format(a,b)) 3.日期计算 import datetime as dt impo ...

  8. angular笔记_3

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. js获取form元素,不使用id

    <form method="post" name="form"> <input type="text" name=&quo ...

  10. 【DWM1000】 非官方开源定位代码bitcraze

    蓝点DWM1000 模块已经打样测试完毕,有兴趣的可以申请购买了,更多信息参见 蓝点论坛 正文: 最近关注DWM1000 定位,一方面在看DWM1000 官方提供的代码,也在四处网上找资料看资料. 其 ...