Delphi: DateTimeToStr output with zero time (midnight) -


i have found similar question here, unrelated trying do. have done lot of research on internet , have determined delphi working designed or intended, omits time if time zero. have application displays date & time in listview, , when time midnight, doesn't show 00:00:00, , therefore making results uneven , out of place.

the way i've gotten around still locale independant add microsecond time, see sample code:

program test11;  {$apptype console} {$r *.res}  uses   system.sysutils, winapi.windows;  begin   try     writeln(datetimetostr(44167, tformatsettings.create(getthreadlocale)));     writeln(datetimetostr(44167.00000001, tformatsettings.create(getthreadlocale)));     readln;   except     on e: exception       writeln(e.classname, ': ', e.message);   end;  end. 

and subsequent output:

02/12/2020 02/12/2020 00:00:00 

the question - there better, more programatically correct way achieve this?

running delphi xe6

you can use formatdatetime function more control on date time formatting.

formatdatetime('ddddd tt', 44167, tformatsettings.create); 

note: there no need call tformatsettings.create(getthreadlocale) locale parameter because plain tformattsettings.create call internally use getthreadlocale on windows platform.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -