Windows 获取文件操作时间的方法
来源:互联网 发布:ubuntu dhcp server 编辑:程序博客网 时间:2024/06/06 04:32
一、获取文件的修改时间
/*
typedef struct _WIN32_FIND_DATAA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;//获取文件创建时间
FILETIME ftLastAccessTime;//获取文件访问时间
FILETIME ftLastWriteTime;//获取文件修改时间
DWORD nFileSizeHigh;//获取文件大小高32位
DWORD nFileSizeLow;//获取文件大小低32位
DWORD dwReserved0;
DWORD dwReserved1;
CHAR cFileName[ MAX_PATH ];
CHAR cAlternateFileName[ 14 ];
#ifdef _MAC
DWORD dwFileType;
DWORD dwCreatorType;
WORD wFinderFlags;
#endif
} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
*/``
举例:
#include<afx.h>////头文件include<afx.h>
int main(int argc,char *argv[])
{
WIN32_FIND_DATA ffd ;
//Filename可以为文件或者文件夹,如果为文件夹则必须保证末尾没有文件分隔符‘\\’。
char Filename[128]="D:\\文件测试.txt";
HANDLE hFind = FindFirstFile(Filename,&ffd);
printf("Filename=%s\r\n",ffd.cFileName);//打印文件名字
printf("FileSize=%d\r\n",ffd.nFileSizeLow);//如果不是文件夹:打印文件大小(单位:字节)
SYSTEMTIME stUTC, stLocal;//UTC时间变量,当地时间变量
FileTimeToSystemTime(&(ffd.ftLastWriteTime), &stUTC);//获取最后一次修改时间,获取UTC格林威治时间
printf("stUTC:%d. %d %d, %d:%d\r\n",
stUTC.wDay,
stUTC.wMonth,
stUTC.wYear,
stUTC.wHour,
stUTC.wMinute
);//显示格林威治UTC时间
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);//时间转换,转换为当地时间
//显示当地时间
printf("stLocal:%d. %d %d, %d:%d\r\n",stLocal.wDay,stLocal.wMonth,stLocal.wYear,stLocal.wHour,stLocal.wMinute);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);//时间转换,转换为当地时间
printf("stLocal:%d. %d %d, %d:%d\r\n",
stLocal.wDay,
stLocal.wMonth,
stLocal.wYear,
stLocal.wHour,
stLocal.wMinute
);//显示当地时间
return 0;
}
2: 得到系统时间日期(使用GetLocalTime)
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("%4d-%2d-%2d",st.wYear,st.wMonth,st.wDay);
strTime.Format("%2d:%2d:%2d",st.wHour,st.wMinute,st.wSecond);
3.使用GetTickCount//获取程序运行时间
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)
Sleep(500); long t2=GetTickCount();//程序段结束后取得系统运行时间(ms)
str.Format("time:%dms",t2-t1);//前后之差即 程序运行时间
AfxMessageBox(str);//获取系统运行时间
long t=GetTickCount();
CString str,str1;
str1.Format("系统已运行 %d时",t/3600000);
str=str1; t%=3600000;
str1.Format("%d分",t/60000);
str+=str1; t%=60000;
str1.Format("%d秒",t/1000);
str+=str1; AfxMessageBox(str);
- Windows 获取文件操作时间的方法
- windows获取时间方法
- c++获取windows时间的方法
- c++获取windows时间的方法
- Windows VC获取准确时间的方法
- C++获取Windows时间方法的总结
- VC获取文件时间信息的方法
- c++获取windows时间的方法(转)
- c++获取WINDOWS时间的方法(转)
- Windows下c++获取系统时间的三种方法
- C++标准库获取时间、简单的文件操作
- 时间的获取方法
- 获取时间的方法
- Java 通过 JNA (Java Native Access) 获取、设置 Windows 操作系统的文件创建时间、文件修改时间、文件访问时间
- 文件读取、获取随机数、转换中文时间的方法
- 获取windows时间的程序
- pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法
- Windows中快速获取文件目录的方法
- java中StringBuilder、StringBuffer、String类之间的关系
- Progressbar的使用以及ListView的使用
- 创建DLL文件 以及 动态加载和静态加载 以及两者之间的区别
- 使用IDEA将本地项目提交到svn上
- map的整理——面试问题
- Windows 获取文件操作时间的方法
- C/C++常用算法【C语言顺序查找(顺序表)】【2】
- jasmine中的matchers
- 版納遐想
- Android 记录-点滴
- 文章标题
- 关于安转android studio 在选择JDK找不到路径的问题
- String 类的用法
- Clob Class 介绍