3

How do I retrieve the actual date from the StackOverflow API creation_date field?

The date depicted via their API is an integer:

"creation_date": 1288523078

However, I would like to convert the integer into an actual DateTime value.

I saw this link. But it's still not clear to me.

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
  • 1
    Im not surprised you're puzzled - I cant see a date in that at all – BugFinder Nov 29 '17 at 10:44
  • Possible duplicate of [StackExchange API - Deserialize Date in JSON Response](https://stackoverflow.com/questions/23380182/stackexchange-api-deserialize-date-in-json-response) – Brock Adams Nov 29 '17 at 19:15

1 Answers1

3

As stated in docs:

All dates in the API are in unix epoch time, which is the number of seconds since midnight UTC January 1st, 1970

To convert to .NET date time, do this:

int apiDate = 1288523078;
// `date` is UTC date here, if you need it in local timezone
//  call ToLocalTime() at the end
var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(apiDate);
Evk
  • 98,527
  • 8
  • 141
  • 191