秒的转换函数(50分)

  • 主题发起人 主题发起人 wuxin
  • 开始时间 开始时间
W

wuxin

Unregistered / Unconfirmed
GUEST, unregistred user!
有什么函数把秒转换成天<br>如:4232127就是48天23小时35分27秒<br>写个例子,用label显示出来
 
先除60秒(余数为秒),再除60分(余数为分),再除24小时(余数为小时),剩下就是天数,这样一直除下去呗。
 
function SecToDate(Sec:integer):String;<br>var<br>&nbsp; D,h,m,s:Integer;<br>&nbsp; Str:string;<br>begin<br>&nbsp; str:='%d天%d小时%d分%d秒';<br>&nbsp; s:=sec mod 60;<br>&nbsp; m:=Trunc((Sec-s)/60) Mod 60;<br>&nbsp; h:=Trunc((sec-s-m*60)/(60*60)) mod 24;<br>&nbsp; d:=Trunc(Sec/(24*60*60));<br>&nbsp; result:=format(str,[d,h,m,s]);<br>end;
 
以下两个是本人用的时间计算函数<br>FUNCTION SYS_SECS(Sec: ShortString) :Integer; export;<br>Var H , M , S : Integer;<br>Begin<br>&nbsp; &nbsp; //HH:MM:SS<br>&nbsp; &nbsp; H:=StrToInt(Copy(Sec,1,2))*3600;<br>&nbsp; &nbsp; M:=StrToInt(Copy(Sec,4,2))*60;<br>&nbsp; &nbsp; S:=StrToInt(Copy(Sec,7,2));<br>&nbsp; &nbsp; Result:=H+M+S;<br>End;<br><br>FUNCTION TIMEApart(Start,Ends :ShortString):String; export;<br>Var X, H, M ,S: Integer;<br><br>Begin<br>&nbsp; &nbsp; If SYS_SECS(Ends) &lt;SYS_SECS(Start) then<br>&nbsp; &nbsp; &nbsp; &nbsp;X:=86400+SYS_SECS(Ends)-SYS_SECS(Start)<br>&nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp;X:=SYS_SECS(Ends)-SYS_SECS(Start);<br><br>&nbsp; &nbsp; &nbsp;H:=Trunc(X/3600) Mod 24;<br>&nbsp; &nbsp; &nbsp;M:=Trunc(X/60)-(Trunc(X/60) div 60)* 60;<br>&nbsp; &nbsp; &nbsp;S:=X -(X div 60)*60;<br>&nbsp; &nbsp; &nbsp;Result:=_StrZero(H,2)+':'+_StrZero(M,2)+':'+_StrZero(S,2);<br>End;<br>
 
同意 app2001<br>再试试 formatdatetime('dd',9340234)
 
const<br>&nbsp; iMin = 60;<br>&nbsp; iHour = 3600;<br>&nbsp; iDay = 86400;<br>var<br>&nbsp; theTime : Integer; &nbsp;// 假设时间(秒)<br>begin<br>&nbsp; theTime := 4232127;<br>&nbsp; theDay := theTime div iDay; // 日<br>&nbsp; theHour := (theTime mod iDay) div iHour;// 小时<br>&nbsp; theMin := (theTime mod iHour) div iMin;//分<br>&nbsp; theSec := theTime mod iMin;//秒<br>end;
 
秒转换成天<br>a:=1/24/3600<br>FormatDateTime('dd',a*xx);
 
Highpeak的最好用.<br>一起谢谢你们
 
后退
顶部