【发布时间】:2016-02-11 20:13:35
【问题描述】:
我正在尝试通过 C# 获取图片 instagram 的发布时间。
例如,我从服务器 (JSON) 获得了下一个字符串:{"created_time":"1447156299","text":".........}
现在几点了?
【问题讨论】:
标签: c# json interface unix-timestamp
我正在尝试通过 C# 获取图片 instagram 的发布时间。
例如,我从服务器 (JSON) 获得了下一个字符串:{"created_time":"1447156299","text":".........}
现在几点了?
【问题讨论】:
标签: c# json interface unix-timestamp
你可以这样做:
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);
输出 1113211532 UNIX timestamp
2005 年 4 月 11 日上午 9:25
输出 1447156299 UNIX timestamp
2015 年 11 月 10 日上午 11:51
【讨论】:
11/10/2015 11:51 AM