0

How can I convert a timestamp given by Event.Timestamp to a Date.

For example I have TimeStamp=72052934740143

I am working with Xamarin.ANdroid. And I need to make this conversion even outside the algorithm.

dou
  • 293
  • 2
  • 3
  • 14
  • 1
    http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa – Ejaz Aug 24 '16 at 13:59
  • Correct me if I am wrong, but Timestamps represents a duration of time, DateTime represents a point in time. Without specifying a starting point in time your question is unanswerable – Steve Aug 24 '16 at 14:03
  • Timestamp gives the duration of time since Jan 01 1970. – dou Aug 24 '16 at 14:09
  • I am not an expert but I think that this is true if we are talking about Unix Timestamp. Instead I think you are dealing with the time passed from the system startup. Indeed, if you look at the answer below, adding Milliseconds or Ticks you get improbable values. – Steve Aug 24 '16 at 14:42

2 Answers2

1

read : https://wpf.2000things.com/tag/timestamp/

The value of the Timestamp property is an int, rather than a DateTime object. The integer represents the number of milliseconds since the last reboot. When the value grows too large to store in the integer object, it resets to 0. This happens every 24.9 days.

private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
    DateTime dt = DateTime.Now;
    dt.AddMilliseconds(e.Timestamp - Environment.TickCount);

    Trace.WriteLine(string.Format("Key DOWN at: {0}", dt.ToString("h:mm:ss.FFF tt")));
}

or in short:

var dt = DateTime.Now.AddMilliseconds(e.Timestamp - Environment.TickCount);
Jan Van Overbeke
  • 250
  • 3
  • 12
0

Try this

double TimeStamp = 72052934740143;
ateTime dt = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(TimeStamp);
Mostafiz
  • 7,243
  • 3
  • 28
  • 42
  • Looks like number is ticks not milliseconds. DateTime dt = DateTime.Parse("1/1/16").AddTicks(72052934740143L); – jdweng Aug 24 '16 at 14:04