English 中文(简体)
UTC支持比较2个档案日/时间
原标题:UTC support for comparing 2 files date/time

我的效用是比较来源和目的地档案日期/时间。 在大多数情况下,这都是在比较不同时区档案的日期/时间时失败的。 因此,我需要一个UTC日常工作。

视视之,视窗APICTI GetFiletime将支持这项工作。 我也发现了这一包裹程序,但在2010年Delphi汇编时,它坠毁了GetFiletime电话。

任何想法? 或者,任何人都有一套处理美国金枪鱼养护委时间区的法规,因此,如果存在不同,我可以把2个名字传给我?

function CompareFileTimes(File1, File2 : String) : LongInt;
var
  F1, F2          : THandle;
  F1_CreateTime,
  F1_LastAccess,
  F1_LastWrite,
  F2_CreateTime,
  F2_LastAccess,
  F2_LastWrite    : PFileTime;
begin
  //Initialize all variables
  F1 := 0;
  F2 := 0;

  //Since these are pointers, we have to
  //allocate memory for the FileTime structures
  GetMem(F1_CreateTime, SizeOf(TFileTime));
  GetMem(F1_LastAccess, SizeOf(TFileTime));
  GetMem(F1_LastWrite, SizeOf(TFileTime));
  GetMem(F2_CreateTime, SizeOf(TFileTime));
  GetMem(F2_LastAccess, SizeOf(TFileTime));
  GetMem(F2_LastWrite, SizeOf(TFileTime));

  //Fill the structures with nulls for now
  FillChar(F1_CreateTime, SizeOf(TFileTime), #0);
  FillChar(F1_LastAccess, SizeOf(TFileTime), #0);
  FillChar(F1_LastWrite, SizeOf(TFileTime), #0);
  FillChar(F2_CreateTime, SizeOf(TFileTime), #0);
  FillChar(F2_LastAccess, SizeOf(TFileTime), #0);
  FillChar(F2_LastWrite, SizeOf(TFileTime), #0);

  //Get file handles for the files in question
  //Notice that even though we re using CreateFile
  //the open disposition for the file is OPEN_EXISTING
  F1 := CreateFile(PChar(F1), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  F2 := CreateFile(PChar(F2), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  //Get the file times for the files.
  GetFileTime(F1, F1_CreateTime, F1_LastAccess, F1_LastWrite);
  GetFileTime(F2, F2_CreateTime, F2_LastAccess, F2_LastWrite);

  //Assign the function s result to comparison
  //-1, File1 is younger than File2
  //0, File1 is the same as File2
  //+1 File1 is older than File2
  Result := CompareFileTime(F1_CreateTime^, F2_CreateTime^);

  //Free the memory allocated to the pointers
  FreeMem(F1_CreateTime, SizeOf(TFileTime));
  FreeMem(F1_LastAccess, SizeOf(TFileTime));
  FreeMem(F1_LastWrite, SizeOf(TFileTime));
  FreeMem(F2_CreateTime, SizeOf(TFileTime));
  FreeMem(F2_LastAccess, SizeOf(TFileTime));
  FreeMem(F2_LastWrite, SizeOf(TFileTime));
end;

任何帮助都将受到高度赞赏。

最佳回答

《2010年德尔菲》已经包含一个容易的包裹,可以让世界金枪鱼委的时间用于奥料。 pas。 这里是比较UTC生成时间的法典的一部分。

uses
  IOUtils, DateUtils;

function CompareFileCreationTimeUtc(const aFile1, aFile2: String): integer;
var
  lCreationTime1: TDateTime;
  lCreationTime2: TDateTime;
begin

  lCreationTime1 := TFile.GetCreationTimeUtc(aFile1);
  lCreationTime2 := TFile.GetCreationTimeUtc(aFile2);

  Result := CompareDateTime(lCreationTime1, lCreationTime2);

end;
问题回答

如果你不希望使用常规和习惯做法,那么你的职能应当像(未测试)一样加以纠正。

function CompareFileTimes(File1, File2 : String) : LongInt;
var
  F1, F2: THandle;
  F1_CreateTime, F2_CreateTime: TFileTime;
begin
  //Fill the structures with nulls for now
  ZeroMemory(@F1_CreateTime, SizeOf(TFileTime));
  ZeroMemory(@F2_CreateTime, SizeOf(TFileTime));

  //Get file handles for the files in question
  //Notice that even though we re using CreateFile
  //the open disposition for the file is OPEN_EXISTING
  F1 := CreateFile(PChar(File1), 0, FILE_SHARE_READ , nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  F2 := CreateFile(PChar(File2), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  if (F1=INVALID_HANDLE_VALUE) or (F1=INVALID_HANDLE_VALUE) then
    RaiseLastOSError;

  //Get the file times for the files.
  if not GetFileTime(F1, @F1_CreateTime, nil, nil) or
     not GetFileTime(F2, @F2_CreateTime, nil, nil) then
    RaiseLastOSError;
  //Assign the function s result to comparison
  //-1, File1 is younger than File2
  //0, File1 is the same as File2
  //+1 File1 is older than File2
  Result := CompareFileTime(F1_CreateTime, F2_CreateTime);
end;




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签