我正在使用PHP / JavaScript的组合从Twitter获取推文并尝试将created_at响应转换为仅显示月和日。
我对创建日期data[0].created_at
的JSON响应返回:
Wed Oct 15 21:30:47 +0000 2014
我想将其转换为:
Oct 15
是否可以在JavaScript中执行此操作?谢谢。
答案 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(' ');