witam.
Jak uzyskać za pomocą delphi znacznik czasu (timestamp) taki jaki jest do uzyskania w php funkcją time().
witam.
Jak uzyskać za pomocą delphi znacznik czasu (timestamp) taki jaki jest do uzyskania w php funkcją time().
Może jakiś konkretny przykładzik? Jak bym wiedział jak to zrobić to bym tutaj chyba nie pisał...
post usunalem
zwracam chono xss nie doczytałem
A czy ty wiesz co robi funkcja time() w php??
Spróbuj:
function DateTimeToUNIXTime(DelphiTime : TDateTime): LongWord;
var
MyTimeZoneInformation: TTimeZoneInformation;
begin
GetTimeZoneInformation(MyTimeZoneInformation);
Result := round(DelphiTime - StrToDate('01/01/1970') + ((MyTimeZoneInformation.Bias) / (24 * 60))) * (24 * 3600);
end;
a w drugą stronę wygląda to tak:
function UNIXTimeToDateTime(UnixTime: LongWord): TDateTime;
var
TimeZoneInformation: TTimeZoneInformation;
begin
GetTimeZoneInformation(TimeZoneInformation);
Result := StrToDate('01/01/1970') + (UnixTime/(24*3600)) - ((TimeZoneInformation.Bias + TimeZoneInformation.DaylightBias) / (24 * 60));
end;
kod wg Tima Gustafsona
i jeszcze inny kod, Paula Dolanda, + strefy czasowe:
const
DELPHI_DATE_01_01_1970 = 25569;
function UNIXTimeToDateTime(UnixTime: LongWord; localtime : boolean): TDateTime;
var
TimeZoneInformation: TTimeZoneInformation;
offset : TDateTime;
begin
Result := DELPHI_DATE_01_01_1970 + (UnixTime/(24*3600));
// Does NOT do daylight savings time adjustment, I'd need a routine to
// determine if the timestamp is during DST or not.
if localtime then
begin
GetTimeZoneInformation(TimeZoneInformation);
offset := TimeZoneInformation.Bias / (24 * 60); // bias is in minutes
result := result - offset;
end;
end;
function DateTimeToUNIXTime(DelphiTime : TDateTime; localtime : boolean): LongWord;
var
TimeZoneInformation: TTimeZoneInformation;
offset : cardinal;
begin
Result := round( (DelphiTime - DELPHI_DATE_01_01_1970) * (24 * 3600) );
// Does NOT do daylight savings time adjustment, I'd need a routine to
// determine if the timestamp is during DST or not.
if localtime then
begin
GetTimeZoneInformation(TimeZoneInformation);
offset := TimeZoneInformation.Bias * 60; //bias is in minutes
result := result + offset;
end;
end;