Convert local time (10-digit number) to a readable date and time format

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

Here is an example timestamp: "1268927156".

At first glance, there is no logic in this. So I tried to convert it in several ways, but without a good result. This value should provide a time around 11 AM (+ 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 that I cannot remember now.

Is there something stupid here?

Thanks in advance

+5
source share
4 answers

It looks like Unix time.

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

And an example code:

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

This seems to be a Unix timestamp (number of seconds since an era)

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

must indicate the date and time that you were after ...

+2
source

, UNIX, :

UNIX , Unix (1 1970 00:00:00 GMT)

codeproject . :

// 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);
+1

unix, no. 01 1970 .

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

If both timestamps utc and local are the same, the timezone on your PBX is either set to UTC, or your timestamps are really 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 timestamps. You will need to find out which one, so you will know how to convert timestamps from UTC or not.

+1
source

All Articles