【问题标题】:How to know post time of pic in instragram? [duplicate]如何知道图片在 Instagram 中的发布时间? [复制]
【发布时间】:2016-02-11 20:13:35
【问题描述】:

我正在尝试通过 C# 获取图片 instagram 的发布时间。
例如,我从服务器 (JSON) 获得了下一个字符串:
{"created_time":"1447156299","text":".........}
现在几点了?

【问题讨论】:

    标签: c# json interface unix-timestamp


    【解决方案1】:

    你可以这样做:

    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 timestamp

    2005 年 4 月 11 日上午 9:25

    输出 1447156299 UNIX timestamp

    2015 年 11 月 10 日上午 11:51

    【讨论】:

    • 我正在获取当前日期。我认为这是错误的。
    • 在哪里可以插入函数 FromUnixTimeSeconds?
    • 仍在获取当前日期
    • 这是我的输出:11/10/2015 11:51 AM
    • 再试一次?我的输出不是当前日期...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多