Results 1 to 1 of 1
  1. #1
    Guest bluberiblub is an unknown quantity at this point
    Join Date
    2012 Nov
    Thanked 0 Times in 0 Posts
    Rep Power

    [Delphi] Systemtime converting and creating the Unixtime (-stamp)

    So today I'm talking with you about timing ;D
    It's not that easy what it looks like, but it is sometimes really useful.
    First, for the following example, you need a Button and a Memo on your Form.
    I have put this example in the onClick Event from the Button.
    If you understand it, you don't have to use Button's nor Memo's.

    procedure TForm1.Button1Click(Sender: TObject);
    var today: TDateTime;
      FileTime,ft,FileTime2: TFileTime;
      systime,own:  TSystemTime;
      unixTime: int64;
      GetSystemTime(systime);     //Get the System Time. i will come back to this later. But i want the actually one (so we can compare it later to the "today" variable)
                     //GetSystemTime gives us the actually Systemtime (Date & Time) in UTC/GMT
     //  SystemTime is splitted in >>Date<< (with: Year, Month, Day) and >>Time<< (with: Hour, Minute, Second AND Milli Second)
     //  So if we want to create our own Systemtime, we have to fill this specification!
       //today := Time;    //Gives us the actualy Time...       (It's to less information)
       //today := Date;    //Gives us the actualy Date...       (Better, but still to less information)
       today :=now;       //Gives us everything, so we have the actualy Time & Date!!!   (We got the Time in gmt + x; x is the Timezone you are in!)
                          //                                                             (We have the Time which you see on your Computer)
           //If you want to do your own Date & Time, there are some possibilities, for example:
           //today := StrToDateTime('11.11.2012 12:55:31');  //maybe on an american System, it should be: StrToDateTime('11/11/2012 12:55:31');
       //Ok, now let us split this in our own SystemTime:       (an other possibility is, to decode your own Date & Time in here)
        DecodeDate(today, own.wYear, own.wMonth, own.wDay);
        DecodeTime(today, own.wHour, own.wMinute, own.wSecond, own.wMilliSeconds);
            //We would get the Same Effect with the actually time:
            //     today := now;
            //     DateTimeToSystemTime(today, own);      //In "own" we got the actually Date & Time (but with the gmt+x, not the normal gmt Time)
            //With this method we don't have to fill an other TSystemTime variable, it will filled automatically.
            //But remember: With this method, we ONLY have the actually Time just with gmt+x
            //We still have to use LocalFileTimeToFileTime and convert the Time to the file time based on the Coordinated Universal Time (UTC)
                 //SystemTimeToFileTime(own, ft);     //showmessage('filetime:'+Inttostr(Int64(ft)));
                 //LocalFileTimeToFileTime(ft, FileTime); //The LocalFileTimeToFileTime function converts a local file time to a file time based on the Coordinated Universal Time (UTC).
        SystemTimeToFileTime(own, ft);   //Convert our SystemTime to FileTime, as the conversion Method wouldn't say it ;D   (We converted it to Windows Filetime)
        LocalFileTimeToFileTime(ft, FileTime);   //The LocalFileTimeToFileTime function converts a local file time to a file time based on the Coordinated Universal Time (UTC).
    //Ok, did you remember our "GetSystemTime(systime);"  at the beginning? All the stuff above is not necessary, if you only want
    //the actually System Time and didn't want to change something...
    //I just made it at the beginning, because so we can compare it. If i would do it now, the time would maybe different - don't forget, we also take the Milliseconds!
         SystemTimeToFileTime(systime, FileTime2);
    Form1.Memo1.lines.add('The filetime''s should be identically!');
    //So now let us transform it to Unix Time:
     unixTime := round((int64(filetime) - int64(116444736000000000)) / 10000000);   
      // 11644473600 ==  1. Januar 1901 00:00:00    
     //If you don't understand it, then look on wikipedia for "Unix time"
     //I couldn't Post you the Link, because of the insufficient of my Postcount ~.~                      
     Form1.Memo1.lines.add('Unix Time(-Stamp) is: '+ IntToStr(unixTime));

Similar Threads

  1. [Delphi] Creating a Simple Game Trainer
    By Dwar in forum Delphi
    Replies: 21
    Last Post: 2012-07-24, 01:38 PM
  2. [Delphi] Delphi elementclient inject
    By marcelo380 in forum Perfect World
    Replies: 0
    Last Post: 2012-06-08, 08:13 PM
  3. [C++] Converting X,Y coords from a float into a DWORD?
    By tacaovo in forum C/C++
    Replies: 4
    Last Post: 2011-12-08, 12:35 PM
  4. [Delphi] Creating DLLs
    By Dwar in forum Delphi
    Replies: 0
    Last Post: 2010-11-04, 08:58 AM
  5. Replies: 0
    Last Post: 2010-10-27, 11:56 AM
Visitors found this page by searching for:

unix time stamp convert delphi tutorial

delphi convert utc time to timestamp GetSystemTime

localfiletimetofiletime delphi

delphi filetime unixtime

delphi unix timestamp timezone

delphi converting unix timestamp to date gmt 2

LocalFileTimeToFileTime freepascal


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts