如何从FTP服务器上获得格式为"2002/07/23 18:02:00"的文件修改日期?(50分)

  • 主题发起人 主题发起人 漠风
  • 开始时间 开始时间

漠风

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI6.0中,用NMFTP控件,怎样才能从FTP服务器上获得格式为"2002/07/23 18:02:00"
的文件修改日期。我用nmftp1.FTPDirectoryList.ModifDate只能获得"Apr 27 15:32"的
文件修改日期。还请各位高手赐教。
 
TMyFTPItem = record
a1:string; //文件属性
a2:string; //文件版本=1
a3:string; //文件建立者 ftp
a4:string; //文件拥有者 ftp
a5:string; //文件尺寸
a6:string; //文件建立月份
a7:string; //文件建立日期
a8:string; //文件建立时间 或 年分
a9:string; //文件名称
fdatetime:tdatetime;
end;


function mreadftp(const mftpstr:string;var Myftp:TMyFTPItem):boolean;
var mstr:string; i,j:integer;
mmonth:array [0..11] of string;
begin
result:=false;
if trim(mftpstr)='' then exit;
if not (mftpstr[1] in ['d','-','l']) then exit;
mmonth[0]:='january';
mmonth[1]:='february';
mmonth[2]:='march';
mmonth[3]:='april';
mmonth[4]:='may';
mmonth[5]:='june';
mmonth[6]:='july';
mmonth[7]:='august';
mmonth[8]:='september';
mmonth[9]:='october';
mmonth[10]:='november';
mmonth[11]:='december';
mstr:=Trim(mftpstr+'#');
i:=pos(' ',mstr);
Myftp.a1:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a2:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a3:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a4:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a5:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a6:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
i:=pos(' ',mstr);
Myftp.a7:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
if length(Myftp.a7)=1 then Myftp.a7:='0'+Myftp.a7;
i:=pos(' ',mstr);
Myftp.a8:=copy(mstr,1,i-1); mstr:=trim(copy(mstr,i+1,length(mstr)));
Myftp.a9:=copy(mstr,1,length(mstr)-1);
if pos(':',Myftp.a8)>1 then begin //myftp.a8 as time or as year
for i:=0 to 11 do
if pos(LowerCase(Myftp.a6),mmonth)=1 then
break;
inc(i);
if strtoint(inttostr(i)+Myftp.a7)>strtoint(formatdatetime('mmdd',now)) then
j:=strtoint(formatdatetime('yyyy',now))-1
else j:=strtoint(formatdatetime('yyyy',now));
Myftp.fdatetime:=strtodatetime(inttostr(j)+'-'+inttostr(i)+'-'+Myftp.a7+' '+Myftp.a8);
end else begin
for i:=0 to 11 do
if pos(LowerCase(Myftp.a6),mmonth)=1 then
break;
inc(i);
Myftp.fdatetime:=strtodatetime(Myftp.a8+'-'+inttostr(i)+'-'+Myftp.a7);
end;

//if is linux then add: myftp.fdatetime:=myftp.fdatetime+8/24;

result:=true;
end;
 
function FormatNTime(S: String): String;
var Year, Month, Day: String;
Times,CYS: String;
I: Integer;
C_Year,Temp1,temp2:Word;
begin
DecodeDate(Date, C_Year, Temp1, Temp2);
CYS:=inttostr(C_year);
try
case S[1] of
'J':
if S[2] = 'a' then Month := '1' else
if S[3] = 'n' then Month := '6' else Month := '7';
'F':
Month := '2';
'M':
if S[3] = 'r' then Month := '3' else Month := '5';
'A':
if S[2] = 'p' then Month := '4' else Month := '8';
'S':
Month := '9';
'O':
Month := '10';
'N':
Month := '11';
'D':
Month := '12';
end;

I := Pos(' ', S);
Delete(S, 1, I);
while S[1] = ' ' do Delete(S, 1, 1);
Day := Trim(Copy(S, 1, 2));
// if Length(Day) = 1 then Day := Day;

if S[3] = ' ' then Delete(S, 1, 3) else Delete(S, 1, 2);

I := Pos(':', S);
if I = 0 then
begin
Year := Trim(S);
{$ifndef Y2K_DATE}
Delete(Year, 1, 2);
{$endif}
Times := '12:00 AM';
end
else
begin
Year := CYS;
if (month>inttostr(temp1)) or ((month=inttostr(temp1)) and (day>inttostr(temp2))) then
Year:=inttostr(strtoint(Year)-1);

Times := Trim(S);
if Length(Times) = 5 then
begin
I := StrToInt(Copy(Times, 1, 2));
if I > 12 then
begin
Delete(Times, 1, 2);
Times := IntToStr(I - 12) + Times + ' PM';
end
else
begin
Times := Times + ' AM';
end;
if Times[1] = '0' then Delete(Times, 1, 1);
end
else
begin
Times := Times + ' AM';
end;
end;
Result := Year + '/' + Month + '/' + Day + ' ' + Times;
except
Result := DefaultDateTime;
end;
end;
 
多谢各位高手的相助,小弟感激不尽。无奈手中的分数太少,不然定会给各位大哥多加几百大分。
 
多谢各位高手的相助,小弟感激不尽。无奈手中的分数太少,不然定会给各位大哥多加几百大分。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
601
import
I
I
回复
0
查看
770
import
I
后退
顶部