请输入您要查询的百科知识:

 

词条 文件时间
释义

文件时间是文件在创建,修改,访问的时间,

本地文件时间,文件从别的机器拷贝到本地机,本机对文件时间的影响称为文件时间,

系统时间,是本地机的系统内部时间,精确到毫秒。

本地时间与UTC(世界协调时间)的转换

此函数获取系统时间

void CLog::GetSysTime(SYSTEMTIME* lpSysTime)//获得系统时间

{

FILETIME CurFileTime;

::GetSystemTimeAsFileTime(&CurFileTime);//GetSystemTimeAsFileTime 首先获得系统时间 UTC格式

::FileTimeToLocalFileTime(&CurFileTime,&CurFileTime);//FileTimeToLocalFileTime 将UTC文件时间转换成本地时间

::FileTimeToSystemTime(&CurFileTime,lpSysTime);// FileTimeToSystemTime 将64位文件时间转换成系统时间格式(UTC)

}

在Window系统中,时间日期本人知道的有以下数种

1.SystemTime:

system time is expressed in Coordinated Universal Time (UTC)

2.LocalTime:

指的是local PC的时间日期,即vb Date() Time()所传回的日期时间

3.FileTime :

文件储存的时间格式前面两种日期的格式都是Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As IntegerEnd Type这TYPE SYSTEMTIME的格式够清楚了,而FileTime则是Type FileTime dwLowDateTime As Long dwHighDateTime As LongEnd TypeThe FILETIME structure is a 64-bit value representing the number of100-nanosecond intervals since January 1, 1601

这三个时间是可以做转换的,LocalTime对SystemTime最简单SystemTime = LocalTime + 时间差 (以台湾来说 时间差 = -8小时)

我们可以用GetTimeZoneInformation()来取得时间差。而SystemTime和FileTime间的转换则可用FileTimeToSystemTime() SystemTimeToFileTime()来转换。剩下的就是更动时间的部份,那使用SetFileTime来完成

SetFileTime(

HANDLE hFile, // identifies the file

CONST FILETIME * lpftCreation, // time the file was created

CONST FILETIME * lpftLastAccess, // time the file was last accessed

CONST FILETIME * lpftLastWrite); // time the file was last written

如果不想更动日期,相对应的参数传Null进去 。

另可参考读取文件建立时间及存取时间'以下程式在Form,需 textBox * 1 Command Button * 1Option ExplicitPrivate hFile As LongPrivate Sub Command1_Click()Dim lpct As FileTime, lplac As FileTime, lplwr As FileTimeDim ofs As OFSTRUCTDim tZone As TIME_ZONE_INFORMATIONDim ft As SYSTEMTIMEDim dtdate As DateDim bias As LonghFile = OpenFile("c:\\prn2", ofs, OF_READWRITE)Call GetTimeZoneInformation(tZone)bias = tZone.bias ' 时间差, 以「分」为单位'计算出Coordinated Universal Time (UTC).dtdate = CDate(Text1.Text) + TimeSerial(0, bias, 0)ft.wYear = Year(dtdate)ft.wMonth = Month(dtdate)ft.wDay = Day(dtdate)ft.wHour = Hour(dtdate)ft.wMinute = Minute(dtdate)ft.wSecond = Second(dtdate)ft.wDayOfWeek = WeekDay(dtdate)ft.wMilliseconds = 0Call SystemTimeToFileTime(ft, lplwr)'更动hFile的时间,

第2个参数改Create DateTime'

第3个参数改Last Access DateTime'

第四个参数改Last Modify DateTimeCall SetFileTime(hFile, ByVal 0, ByVal 0, lplwr)Call CloseHandle(hFile)End SubPrivate Sub Form_Load()Text1.Text = "1998/06/03 5:50:10 AM"End SubOption ExplicitPublic Const OFS_MAXPATHNAME = 128Public Const OF_READ = &H0Public Const OF_READWRITE = &H2Type OFSTRUCT cBytes As Byte fFixedDisk As Byte nErrCode As Integer Reserved1 As Integer Reserved2 As Integer szPathName(OFS_MAXPATHNAME) As ByteEnd TypeType SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As IntegerEnd TypeType FileTime dwLowDateTime As Long dwHighDateTime As LongEnd TypeType TIME_ZONE_INFORMATION bias As Long StandardName(32) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(32) As Integer DaylightDate As SYSTEMTIME DaylightBias As LongEnd TypeDeclare Function GetTimeZoneInformation Lib "kernel32" _ (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongDeclare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _ lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As LongDeclare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongDeclare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As Any, lpLastAccessTime As Any, lpLastWriteTime As Any) As LongDeclare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FileTime) As LongDeclare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/12/23 9:32:02