我想将Instagram API中created_time的字符串JSON对象解析为可读日期。我读了几篇帖子说new Date("1923111")
(无论created_time是什么)都会解决这个问题,但我收到了无效的日期错误。
我想使用Moment.js来解析它:
moment.unix(created_time).format("MMMM D, YYYY")
但我收到1469576855000-20en
作为输出。有没有其他方法可以做到这一点?
答案 0 :(得分:1)
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;
答案 1 :(得分:0)
var date = new Date(parseInt(created_time) * 1000);
var month = (date.getMonth()+1);
var date = date.getDate();
var fullYear = date.getFullYear();