9
var timestamp: Longint;
timestamp := Round((Now() - 25569.0 {Unix start date in Delphi terms}) * 86400);
里面我是用在一些MySql的东西主键。
但我还想格式化日期/时间,就像PHP's date() function那样。
有没有人有代码段或URL?
var timestamp: Longint;
timestamp := Round((Now() - 25569.0 {Unix start date in Delphi terms}) * 86400);
里面我是用在一些MySql的东西主键。
但我还想格式化日期/时间,就像PHP's date() function那样。
有没有人有代码段或URL?
您从DateUtils.pas
寻找function DateTimeToUnix(const AValue: TDateTime): Int64;
和
function UnixToDateTime(const AValue: Int64): TDateTime;
功能
TDateTime类型值可以通过FormatDateTime功能
被格式化这是更快
// 4x faster than dateutils version
function UNIXTimeToDateTimeFAST(UnixTime: LongWord): TDateTime;
begin
Result := (UnixTime/86400) + 25569;
end;
// 10x faster than dateutils version
function DateTimeToUNIXTimeFAST(DelphiTime : TDateTime): LongWord;
begin
Result := Round((DelphiTime - 25569) * 86400);
end;
+1谢谢。我不会经常这样做,但这对知道 – Mawg 2011-02-23 07:25:16
很有用。请注意,DateTimeToUNIXTimeFAST与DateUtils版本略有不同,如果毫秒= 500..999,则DateUtils将倒退,而FAST版本将向下舍入第二。 – hikari 2014-01-05 20:37:49
结果:= Trunc(((DelphiTime - 25569)* 86400); – wittrup 2014-03-06 18:13:00