Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 660
Terry Avatar asked Mar 19 '10 13:03

Terry


People also ask

How do I convert a datetime to a specific format?

The ToString() method of the DateTime class is used to convert a DateTime date object to string format. The method takes a date format string that specifies the required string representation.

How do I convert 8 digits to dates in Excel?

On the Data tab of the ribbon, click Text to Columns. Click Next >, then Next > again. Under 'Column data format', select Date, then select YMD from the drop-down next to the Date option button. Click Finish.

How do I convert a time stamp to a date in python?

Converting timestamp to datetime We may use the datetime module's fromtimestamp() method to convert the timestamp back to a datetime object. It returns the POSIX timestamp corresponding to the local date and time, as returned by time. time().


1 Answers

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 );
like image 67
Carra Avatar answered Sep 17 '22 21:09

Carra