[delphi] jak uzyskać znacznik czasu timestamp

0

witam.

Jak uzyskać za pomocą delphi znacznik czasu (timestamp) taki jaki jest do uzyskania w php funkcją time().

0

Może jakiś konkretny przykładzik? Jak bym wiedział jak to zrobić to bym tutaj chyba nie pisał...

0

post usunalem
zwracam chono xss nie doczytałem

0

A czy ty wiesz co robi funkcja time() w php??

0

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

0

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; 

1 użytkowników online, w tym zalogowanych: 0, gości: 1