0

I am using CodeSite. In the raw log files, i see below TimeStamp format -- how do i convert this to Actual DateTime? What TimeStamp format is this? This is not Epoch TimeStamp format.

I am trying to convert below TimeStamp to Date.

TimeStamp=736843.29124842

This should convert to 5/29/2018 8:05:24.842 (MST).

Amyn
  • 83
  • 1
  • 2
  • 10
  • 2
    TimeStamp.Date := 736843; TimeStamp.Time := 29124842; Caption := DateTimeToStr(TimeStampToDateTime(TimeStamp)) – FredS Jun 01 '18 at 23:17
  • In addition to what @FredS said, take a look at the documentation for [System.SysUtils.TTimeStamp](http://docwiki.embarcadero.com/Libraries/XE7/en/System.SysUtils.TTimeStamp). Note that `TTimeStamp` is a record with two fields, `Time: integer` and `Date: integer` and not a real value as `Codesite` write it in their raw log. – Tom Brunberg Jun 02 '18 at 05:56
  • CodeSite has no logging method for `TTimeStamp` (checked current version 5.3.2). So either you made up extra logging method for this, or converted the logged value in some way. In either case, it's your code that does this conversion. – Victoria Jun 02 '18 at 12:54
  • @Victoria - question is about the time stamp of any log entry. – Sertac Akyuz Jun 02 '18 at 13:13
  • @Sertac, ah, read from a raw log file. I missed that. – Victoria Jun 02 '18 at 16:44

1 Answers1

1

You're not supposed to parse those files by yourself. But well, if you want, here's the function which parses the CodeSite message timestamp (based on the TCodeSiteMessage.SetAsString method timestamp parsing code, CodeSite version 5.3.2):

function CodeSiteTimeStampToDateTime(const Value: string): TDateTime;
var
  P: Integer;
  T: TTimeStamp;
begin
  P := Pos('.', Value);
  if (P > 0) and TryStrToInt(Copy(Value, 1, P - 1), T.Date) and TryStrToInt(Copy(Value, P + 1, 20), T.Time) then
    Result := TimeStampToDateTime(T)
  else
    raise Exception.Create('Invalid timestamp value.');
end;

Of course this is a CodeSite internal implementation and may be subject to change.

Victoria
  • 7,822
  • 2
  • 21
  • 44
  • I was able to parse the TimeStamp in C# as below: string[] s = TimeStamp.ToString().Split('.'); DateTime dt = (new DateTime()).AddMilliseconds(double.Parse(s[1])); var epoch = (new DateTime(0001, 01, 01)).Add(dt.TimeOfDay); var yourDate = epoch.AddDays(double.Parse(s[0]) - 1); – Amyn Jun 22 '18 at 23:50