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?
Asked
Active
Viewed 77 times
2

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

user1915161
- 71
- 3
1 Answers
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
-
I am getting current date. i think this is wrong. – user1915161 Nov 10 '15 at 20:24
-
where can i insert function FromUnixTimeSeconds? – user1915161 Nov 10 '15 at 20:33
-
still getting the current date – user1915161 Nov 10 '15 at 20:38
-
This is my output : `11/10/2015 11:51 AM` – Skizo-ozᴉʞS ツ Nov 10 '15 at 20:41
-
Tried again? My output it's not the current date... – Skizo-ozᴉʞS ツ Nov 11 '15 at 13:12
-
Shall I update my answer or so? or worked for you? – Skizo-ozᴉʞS ツ Nov 16 '15 at 10:02