Convert local time (10 digit number) to a readable datetime format

Terry picture Terry · Mar 19, 2010 · Viewed 15.5k times · Source

I'm working with pbx for voip calls. One aspect of pbx is that you can choose to receive CDR packages. Those packages have 2 timestamps : "utc" and "local", but both seem to always be the same.

Here's an example of a timestamp : "1268927156".

At first sight, there seems to be no logic in it. So I tried converting it several ways, but with no good result. That value should provide a time around 11am (+1GMT) today.

Things I tried:

  • Datetime dt = new Datetime(number);
  • Timespan ts = new Timespan(number);
  • DateTime utc = new DateTime(number + 504911232000000000, DateTimeKind.Utc)

and some others I can't remember right now.

Am I missing something stupid here?

Thanks in advance

Answer

Carra picture Carra · Mar 19, 2010

This looks like Unix time.

1268927156 = Thu, 18 Mar 2010 15:45:56 GMT

And a code sample:

DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime time = startDate.AddSeconds(1268927156 );