我正在尝试通过C#获取图片instagram的发布时间。
例如,我从服务器获取了下一个字符串(JSON):
{"created_time":"1447156299","text":".........}
现在几点了?
最佳答案
您可以按如下方式进行:
static DateTime ConvertFromUnixTimestamp(double timestamp){
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
您必须将“1447156299”
传递给double,然后您就可以做到这一点。
有关更多信息,请查看此 tutorial
编辑
// 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);
取自 this site
输出带有 1113211532 UNIX 时间戳
4/11/2005 9:25 AM
输出带有 1447156299 UNIX 时间戳
11/10/2015 11:51 AM
关于c# - 如何知道 Instagram 中图片的发布时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33638668/