views:

463

answers:

4

Hey all,

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

+5  A: 

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);
DateTime time = startDate.AddSeconds(1268927156 );
Carra
issue fixed, all great answer, thanks
djerry
+1  A: 

Seems to be a Unix timestamp (no. of seconds since the epoch)

DateTime translated = new DateTime(1970,1,1).AddSeconds(1268927156);

should give you the date and time you were after...

ZombieSheep
+1  A: 

I guess this is a UNIX timestamp, the logic would be the following:

The UNIX timestamp represents the time measured in number of seconds since the Unix Epoch (1st of January 1970 00:00:00 GMT)

There is a codeproject article explaining the conversion. Basically what you need to do would be the following:

// First make a System.DateTime equivalent to the UNIX Epoch.
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
// Add the number of seconds in UNIX timestamp to be converted.
dateTime = dateTime.AddSeconds(timestamp);
Vinz
+1  A: 

That looks like a unix timestamp, which is the no. of seconds since Jan 01,1970.

DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(1268927156);

If both the utc and local timestamps are the same, the timezone on your PBX is either set to UTC, and your timestamps really are UTC, or the timezone is set to UTC but the time is set to your local time, and you get your local time for both of the timestamps. You'll have to figure out which of those so you'll know wether to convert the timestamps from UTC or not.

nos