was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

45 Visitors Online


 
...TDateTime in Unix Timestamp/Zeitstempel konvertieren?
Autor: Thomas Greiner
Homepage: http://www.economx.com
[ Tip ausdrucken ]  

Tip Bewertung (37):  
     


{
  Sometimes you want to communicate with mySQL or other databases using
  the unix timestamp. To solve this difference you may want to convert your
  TDateTime to the unix timestamp format and vice versa.

  Um den in einigen Datenbanken verwendeten Unix Timestamp für die Kommunikation
  mit Delphi nutzbar zu machen, kann man mit dieser Unit das TDateTime Format
  in den Unix Timestamp und umgekehrt umwandeln.
}

unit unix_utils;

interface

implementation

const
  
// Sets UnixStartDate to TDateTime of 01/01/1970
  
UnixStartDate: TDateTime = 25569.0;

function DateTimeToUnix(ConvDate: TDateTime): Longint;
begin
  
//example: DateTimeToUnix(now);
  
Result := Round((ConvDate - UnixStartDate) * 86400);
end;

function UnixToDateTime(USec: Longint): TDateTime;
begin
  
//Example: UnixToDateTime(1003187418);
  
Result := (Usec / 86400) + UnixStartDate;
end;

end.


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners