Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a Unix timestamp in Delphi?

Tags:

delphi

I have

var timestamp: Longint;  
timestamp := Round((Now() - 25569.0 {Unix start date in Delphi terms} ) * 86400);

which I am using as a primary key in some MySql stuff.

But I would also like to format the date/time, like PHP's date() function does.

Does anyone have a code snippet or URL?

like image 879
Mawg says reinstate Monica Avatar asked Dec 12 '10 02:12

Mawg says reinstate Monica


People also ask

What is timestamp in Unix format?

Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC. One of the primary benefits of using Unix time is that it can be represented as an integer making it easier to parse and use across different systems.


1 Answers

You are looking for

function DateTimeToUnix(const AValue: TDateTime): Int64;

and

function UnixToDateTime(const AValue: Int64): TDateTime;

functions from DateUtils.pas

TDateTime value can be formatted by FormatDateTime function

like image 154
kludg Avatar answered Sep 22 '22 08:09

kludg