procedure TForm1.Button1Click(Sender: TObject);
var systime: Tsystemtime;
begin
getLocaltime(systime);
Edit1.text:=inttostr(systime.wMonth)+inttostr(systime.wday)+inttostr(systime.wHour)+inttostr(systime.wMinute)+inttostr(systime.wSecond);
end;得出来的时间格式是(101853640)这是我系统当前时间10月18日5点36分40秒
为什么要把它转换成101853640这种格式?因为需要,计算时差等方面的需求现在遇到一个问题,看,5点36我要让它显示成05如果当前秒数是5,也要让它显示成05,这样计算时差才不会有错,
也就是要让101853640显示成1018053640,求方法,我试了很多,可是实现不了.谢谢大家
var systime: Tsystemtime;
begin
getLocaltime(systime);
Edit1.text:=inttostr(systime.wMonth)+inttostr(systime.wday)+inttostr(systime.wHour)+inttostr(systime.wMinute)+inttostr(systime.wSecond);
end;得出来的时间格式是(101853640)这是我系统当前时间10月18日5点36分40秒
为什么要把它转换成101853640这种格式?因为需要,计算时差等方面的需求现在遇到一个问题,看,5点36我要让它显示成05如果当前秒数是5,也要让它显示成05,这样计算时差才不会有错,
也就是要让101853640显示成1018053640,求方法,我试了很多,可是实现不了.谢谢大家
procedure TForm1.Button1Click(Sender: TObject);
var systime: Tsystemtime;
day,hour,m,s: String;begin
getLocaltime(systime);
if 30 - systime.wDay >20 then
begin
day:='0'+inttostr(systime.wDay);
end
else
begin
day:=inttostr(systime.wDay);
end;
if systime.wHour + 1 < 11 then
begin
hour:='0'+inttostr(systime.wHour);
end
else
begin
hour:=inttostr(systime.wHour);
end;
if systime.wMinute + 1 < 11 then
begin
m:='0'+inttostr(systime.wMinute);
end
else
begin
m:=inttostr(systime.wMinute);
end;
if systime.wSecond + 1 < 11 then
begin
s:='0'+inttostr(systime.wSecond);
end
else
begin
s:=inttostr(systime.wSecond);
end;
Edit1.text:=inttostr(systime.wMonth)+day+hour+m+s;
end;
var systime: Tsystemtime;
begin
getLocaltime(systime);
Edit1.text:=FormatFloat('0#',systime.wMonth)+FormatFloat('0#',systime.wday)+
FormatFloat('0#',systime.wHour)+FormatFloat('0#',systime.wMinute)+FormatFloat('0#',systime.wSecond);
end;
var systime: Tsystemtime;
begin
getLocaltime(systime);
Edit1.text:= Format('%.2d%.2d%.2d%.2d%.2d',[systime.wMonth,systime.wday,systime.wHour,systime.wMinute,systime.wSecond]);
end;
下面这个就足够了
formatdatetime('yyyymmddhhnnss', now);
FormatDateTime('mmddhhnnss', now)如果你一定要systime,那么
var
systime: Tsystemtime;
begin
getLocaltime(systime);
SystemTimeToDateTime(systime);
ShowMessage(FormatDateTime('mmddhhnnss', SystemTimeToDateTime(systime)));
end;不过,还是没有直接Now来的简单