2

I am trying to get the post time of picture instagram by C#.
For example i got the next string from the server (JSON):
{"created_time":"1447156299","text":".........}
what is the time?

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148

1 Answers1

2

You can do it as follows :

static DateTime ConvertFromUnixTimestamp(double timestamp){
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}

You'll have to pass "1447156299" to double and then you'll be able to do it.

For more information check this tutorial

EDIT

// This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25.
double timestamp = 1113211532;

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

// The dateTime now contains the right date/time so to format the string,
// use the standard formatting methods of the DateTime object.
string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();

// Print the date and time
System.Console.WriteLine(printDate);

Taken from this site

Output with 1113211532 UNIX timestamp

4/11/2005 9:25 AM

Output with 1447156299 UNIX timestamp

11/10/2015 11:51 AM

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148