Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   wie aus eigener systemtime richtiges datum machen?? (https://www.delphipraxis.net/107378-wie-aus-eigener-systemtime-richtiges-datum-machen.html)

lbccaleb 26. Jan 2008 19:13


wie aus eigener systemtime richtiges datum machen??
 
hey there,


also da sich ja dieses thema wie auf bestimmte zeit reagieren geklärt hat, hab ich dazu jetzt allerdings noch eine neue frage bzw ein neues problem das da währe :

wie bekomm ich eine eigene tsystemtime, also z.b. systemtime.wday + 12 wieder als funktionierendes datum hinn?? wenn ich es somache, dann würde er bei zb dem 31ten, einen 43 draus machen.. und das geht ja nun wirklich nicht ;-)
wie bekomm ich also hinn, das es wieder ein ordentliches datum ergibt??

dabei ist wieder zu berücksichtigen, das units wie math, dateutils, sysutils, usw NICHT eingebunden werden, also alles wieder rein auf der win32api basierend...

danke schonmal im vorraus..

lbccaleb 26. Jan 2008 20:10

Re: wie aus eigener systemtime richtiges datum machen??
 
nach langem suchen habe ich jetzt was gefunden, nur leider ist das in c++ und genau da drin bin ich ne totale niete ;-(

gibt es jemand der mir das mal nen bissel in deutsch, bzw delpisch umschreiben kann ;-)

working with file time

also das convertieren von systemtime und filetime damit habe ich keine probleme aber wie addiere ich zeiten auf tfiletime?? das raff ich nicht wirklich!!

edit:
das währe das hier:
Zitat:

MORE INFORMATION
The FILETIME structure represents the number of 100-nanosecond intervals since January 1, 1601. The structure consists of two 32-bit values that combine to form a single 64-bit value.

typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;


Note that the FILETIME structure is based on 100-nanosecond intervals. It is helpful to define the following symbols when working with file times. For example:

#define _SECOND ((int64) 10000000)
#define _MINUTE (60 * _SECOND)
#define _HOUR (60 * _MINUTE)
#define _DAY (24 * _HOUR)


Back to the top
Performing Arithmetics with File Times
It is often necessary to perform a simple arithmetic on file times. For example, you might need to know when a file is 30 days old. To perform an arithmetic on a file time, you need to convert the FILETIME to a quadword (a 64-bit integer), perform the arithmetic, and then convert the result back to a FILETIME.

Assuming ft is a FILETIME structure containing the creation time of a file, the following sample code adds 30 days to the time:

ULONGLONG qwResult;

// Copy the time into a quadword.
qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;

// Add 30 days.
qwResult += 30 * _DAY;

// Copy the result back into the FILETIME structure.
ft.dwLowDateTime = (DWORD) (qwResult & 0xFFFFFFFF );
ft.dwHighDateTime = (DWORD) (qwResult >> 32 );

Remko 26. Jan 2008 20:29

Re: wie aus eigener systemtime richtiges datum machen??
 
Just cast the filetime to Int64 and use add/substract operations

lbccaleb 26. Jan 2008 20:35

Re: wie aus eigener systemtime richtiges datum machen??
 
Zitat:

Zitat von Remko
Just cast the filetime to Int64 and use add/substract operations

can you give an example how to do this??

Muetze1 26. Jan 2008 20:47

Re: wie aus eigener systemtime richtiges datum machen??
 
Delphi-Quellcode:
filetime := TFileTime(Int64(filetime) + YourAddition);

lbccaleb 26. Jan 2008 20:49

Re: wie aus eigener systemtime richtiges datum machen??
 
Zitat:

Zitat von Muetze1
Delphi-Quellcode:
filetime := TFileTime(Int64(filetime) + YourAddition);

und was ist genau "youraddition"?? wenn ich einen tag zb hinzufügen will, muss ich + 24 rechnen oder wie??

Remko 26. Jan 2008 20:57

Re: wie aus eigener systemtime richtiges datum machen??
 
Delphi-Quellcode:
const
  _SECOND: int64 = 10000000;
  _MINUTE: Int64 = 600000000;
  _HOUR: Int64 = 36000000000;
  _DAY: Int64 = 864000000000;
var
  ft: FILETIME;
  i: Int64;
begin
  // Set filetime to 0 which means January 1, 1601
  ft.dwLowDateTime := 0;
  ft.dwHighDateTime := 0;

  // inc by 30 days
  ft := TFileTime(Int64(ft) + (30 * _DAY));

lbccaleb 26. Jan 2008 21:11

Re: wie aus eigener systemtime richtiges datum machen??
 
Zitat:

Zitat von Remko
Delphi-Quellcode:
const
  _SECOND: int64 = 10000000;
  _MINUTE: Int64 = 600000000;
  _HOUR: Int64 = 36000000000;
  _DAY: Int64 = 864000000000;
var
  ft: FILETIME;
  i: Int64;
begin
  // Set filetime to 0 which means January 1, 1601
  ft.dwLowDateTime := 0;
  ft.dwHighDateTime := 0;

  // inc by 30 days
  ft := TFileTime(Int64(ft) + (30 * _DAY));

ok thx, das werde ich mal ausprobieren!!

ok thx, i try it!!

lbccaleb 26. Jan 2008 21:48

Re: wie aus eigener systemtime richtiges datum machen??
 
ok alles funzt super, respect :thumb: :thumb: :thumb:

ich hab daraus mal eine function gemacht, also fals es mal einer brauch:



Delphi-Quellcode:
function AddTime(AddTime: TSystemTime; TimeToAdd: int64): TSystemTime;
//TimeToAdd can be this:
//const
//_SECOND: int64 = 10000000;
//_MINUTE: Int64 = 600000000;
//_HOUR: Int64 = 36000000000;
//_DAY: Int64 = 864000000000;
//(_Day * 20)
var
  TempFileTime: FILETIME;
  begin;
    Result := AddTime;
    if SystemTimeToFileTime(AddTime, TempFileTime) then
      begin;
        TempFileTime := TFileTime(Int64(TempFileTime) + TimeToAdd);
        FileTimeToSystemTime(TempFileTime, Result);
      end;
  end;

himitsu 26. Jan 2008 23:57

Re: wie aus eigener systemtime richtiges datum machen??
 
Zitat:

AddTime(AddTime: TSystemTime; TimeToAdd: int64): TSystemTime;
wozu der Umweg über TFileTime?
TSysteTime ist doch ein recht einfaches Format und so schwer sollte das Rechnen damit doch nicht sein?


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:31 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz