Home > Back-end >  The system time can't get
The system time can't get

Time:12-09

A VC to write a DLL function, once after the call, the inside of the Delphi now time will not change, such as call before: S=FormatDatetime (' yyyy/mm/dd hh: nn: ss ', now) can display the current time, normal call DLL, S always values are the same, but, curiously, internal use Windows API function GetLocalTime SysTime () function can access to change the date of the time, such as:
Edit1. Text:=IntToStr (SysTime. WYear)
+ '/' + IntToStr (SysTime. WMonth)
+ '/' + IntToStr (SysTime. WDay)
+ "+ IntToStr (SysTime. WHour)
+ ', '+ IntToStr (SysTime. WMinute)
+ ', '+ IntToStr (SysTime. WSecond);
Can display normally, but as long as the use of the Delphi SysUtils unit function cannot change, such as EncodeDate DateTimeToStr, etc., in the function value is constant, the students encounter such a situation, locking difficulty in the DLL function have??????

CodePudding user response:

This is what you call API, interfere with the New functions of Delphi,
In this way, you can directly use the API function of the system, the time value to be obtained,
GetLocalTime (& amp; A price);//get the local time zone corresponding time
GetSystemTime (& amp; A price);//get the system time (standard time) green

CodePudding user response:

Learned, in charge

CodePudding user response:

reference 1st floor lyhoo163 response:
this is what you call API, interfere with the New functions of Delphi,
In this way, you can directly use the API function of the system, the time value to be obtained,
GetLocalTime (& amp; A price);//get the local time zone corresponding time
GetSystemTime (& amp; A price);//get the system time (standard time) green


Now know that GetLocalTime (SysTime) can get right time, but cannot be converted into a Tdatetime types, including SysUtils unit and time correlation function cannot be used

CodePudding user response:

 
The unit Unit2.

Interface

USES the
Winapi. Windows System. SysUtils, System. Classes,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs;

Type
TForm2=class (TForm)
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form2: TForm2;

Implementation

{$R *. DFM}

Procedure TForm2. FormCreate (Sender: TObject);
Var
P: SYSTEMTIME;
The begin
GetLocalTime (p);
ShowMessage (DateTimeToStr (SystemTimeToDateTime (p)));
end;

End.

CodePudding user response:

Time to stop, not probably, now the function of the first sentence is not GetLocalTime,
No refresh time or custom now function,

CodePudding user response:

Should be no such thing, with S:=FormatDateTime (' c ', Now); Have a try,
  • Related