You are not logged in.
Pages: 1
How do works UnixTimePeriodToString() and UnixMSTimePeriodToString() functions from SynCommons unit?
I need convert some interval (period) of time to string. I try these functions, but I get strange results:
var
  u : TUnixTime;
  ums : TUnixMSTime;
  dt: TDateTime;
  s: string;
begin
  dt := Now() - IncHour(Now(), -3); // three hours period, I mean
  ums := DateTimeToUnixMSTime(dt);
  s := UnixMSTimePeriodToString(ums, ' ');
  Writeln('UnixMSTimePeriodToString: ' + s);
  u := DateTimeToUnixTime(dt);
  s := UnixTimePeriodToString(u, ' ');
  Writeln('UnixTimePeriodToString: ' + s);and I get:
UnixMSTimePeriodToString:  21:00:00.000
UnixTimePeriodToString:  21:00:00why 21 not 3 h?
Offline
You are decreasing the hours twice:
dt := Now() - IncHour(Now(), -3); // three hours period, I meanUse
dt := IncHour(Now(), -3); Offline
I know, but I do it consciously.
What you have proposed is a full date and time from 3 hours ago, e.g. 2019-06-18 13:30
And what I mean is only 3 hours, a time segment (period/interval), not a point on the timeline. 
For example, total working time in the last month.
Offline
Sorry. I understood what you want to do now.
Why not calculate using unixtime directly?
  u := DateTimeToUnixTime(Now) - (DateTimeToUnixTime(Now) - 60*60*3);
  //or 
  //  u := DateTimeToUnixTime(Now) - DateTimeToUnixTime(IncHour(Now,-3));
   Writeln('UnixTimePeriodToString: ', UnixTimePeriodToString(u, ' '));UnixTimePeriodToString: 03:00:00Last edited by macfly (2019-06-18 16:51:09)
Offline
You are right! Thx macfly :-)
Offline
Pages: 1