使用JavaScript转换Twitter的created_at日期?

时间:2014-11-19 19:22:06

标签: javascript json date format

我正在使用PHP / JavaScript的组合从Twitter获取推文并尝试将created_at响应转换为仅显示月和日。

我对创建日期data[0].created_at的JSON响应返回:

Wed Oct 15 21:30:47 +0000 2014

我想将其转换为:

Oct 15

是否可以在JavaScript中执行此操作?谢谢。

1 个答案:

答案 0 :(得分:1)

//split it into an array
//splice and only keep the two words that contain date information
//join it with a space
'Wed Oct 15 21:30:47 +0000 2014'.split(' ').splice(1,2).join(' ');
//in case you need the year too
//get the year by going to the last array index and join that too
var split = 'Wed Oct 15 21:30:47 +0000 2014'.split(' ');
var date = split.splice(1,2);
var year = split[split.length-1];
date.push(year);
date = date.join(' ');