所以我有一个像Wed, 08 May 2013 11:11:30 GMT
这样的字符串。 (仅供参考,它是从XML RSS文件中提取的)我想要的是从上面的字符串到两个变量Wed, 08 May
和11:11
。据我所知,这里有几件事需要做:
除此之外,我不知道该怎么办。有人可以帮忙吗?到目前为止我的代码如下:
$.ajax({
type: 'GET',
url: 'proxy.php',
data: {requrl: "http://feeds.bbci.co.uk/news/rss.xml"},
dataType: 'xml',
success: function (xml) {
$('#newsTimeline').empty();
$(xml).find("item").each(function () {
//for(var i = 0; i < $item.length && i < 5; i++){
var title = $(this).find("title").text();
var description = $(this).find("description").text();
var linkUrl = $(this).find("link_url").text();
var link = "<a href='" + linkUrl + "' target='_blank'>Read More<a>";
$('#feedContainer').append('
<li>\
<time class="cbp_tmtime" datetime="2013-04-10 18:30"><span>4/10/13</span> <span>18:30</span></time>\
<div class="cbp_tmicon cbp_tmicon-phone"></div>\
<div class="cbp_tmlabel">\
<h2>Ricebean black-eyed pea</h2>\
<p>Winter purslane courgette pumpkin quandong komatsuna fennel green bean cucumber watercress. Pea sprouts wattle seed rutabaga okra yarrow cress avocado grape radish bush tomato ricebean black-eyed pea maize eggplant. Cabbage lentil cucumber chickpea sorrel gram garbanzo plantain lotus root bok choy squash cress potato summer purslane salsify fennel horseradish dulse. Winter purslane garbanzo artichoke broccoli lentil corn okra silver beet celery quandong. Plantain salad beetroot bunya nuts black-eyed pea collard greens radish water spinach gourd chicory prairie turnip avocado sierra leone bologi.</p>\
</div>\
</li>\
');
//}
});
}
});
如您所见,我已经删除了标题,说明和阅读更多文字。 proxy.php文件只是一个file_get_contents请求。
答案 0 :(得分:2)
为了获得时间:
var pubDate = "Sun, 27 Mar 2011 20:17:21 +0100";
var date = new Date(pubDate);
var months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var string = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()
var time = date.getHours()+":"+date.getMinutes();
alert(string+"\n"+time);
答案 1 :(得分:0)
var str1="Wed, 08 may 2013 11:11:30 GMT";
var test1 = str1.substring(0,str1.length-17);
alert(test1 );
var test2 = str1.substring(test1.length+4,str1.length-7);
alert(test2 );
检查这是否完美,