gpt4 book ai didi

javascript - Instagram API created_time 与 Moment.js 的最新日期

转载 作者:行者123 更新时间:2023-11-27 22:42:09 24 4
gpt4 key购买 nike

我想将 Instagram API 中的created_time 字符串JSON 对象解析为可读的日期。我读过几篇文章,说 new Date("1923111") (无论created_time 是什么)将解决这个问题,但我收到了无效日期错误。

我想使用 Moment.js 来解析它:

moment.unix(created_time).format("MMMM D, YYYY")

但我收到 1469576855000-20en 作为输出。还有其他方法可以做到这一点吗?

最佳答案

var date = new Date(image.created_time*1000);

m = date.getMonth();
d = date.getDate();
y = date.getFullYear();

var month_names = new Array ( );
month_names[month_names.length] = "01";
month_names[month_names.length] = "02";
month_names[month_names.length] = "03";
month_names[month_names.length] = "04";
month_names[month_names.length] = "05";
month_names[month_names.length] = "06";
month_names[month_names.length] = "07";
month_names[month_names.length] = "08";
month_names[month_names.length] = "09";
month_names[month_names.length] = "10";
month_names[month_names.length] = "11";
month_names[month_names.length] = "12";

var thetime = y + '-' + month_names[m] + '-' + d;

image.created_time = thetime;

return true;

关于javascript - Instagram API created_time 与 Moment.js 的最新日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38668796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com