-1

I has in string format, timestamp 1593339378252, i need convert this, to a normal human date-20.06.2020 I try this code

var timestamp = Convert.ToInt64(dateFrom);

            // Format our new DateTime object to start at the UNIX Epoch
            System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

            // Add the timestamp (number of seconds since the Epoch) to be converted
            dateTime = dateTime.AddSeconds(timestamp);

but if i try convert to int32,16,64 i get System.ArgumentOutOfRangeException

Gregory
  • 49
  • 5
  • https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa – Emanuele Jun 04 '20 at 12:24
  • `DateTime dt = new DateTime(timestamp);` did you try this? – Chetan Jun 04 '20 at 12:24
  • Does this answer your question? [How can I convert a Unix timestamp to DateTime and vice versa?](https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa) – Emanuele Jun 04 '20 at 12:25

2 Answers2

0

It seems that your timestamp actually contains number of milliseconds, not seconds:

new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc).AddMilliseconds(1593339378252)
// on my machine - 28-Jun-20 10:16:18 AM 
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
0

You can use var dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(yourValue);

For more information, also look at the documentation

Sotiris Panopoulos
  • 1,523
  • 1
  • 13
  • 18