gpt4 book ai didi

javascript - 将 RSS pubdate 字符串转换为 jQuery 中的时间和日期

转载 作者:行者123 更新时间:2023-11-30 18:03:07 64 4
gpt4 key购买 nike

所以我有一个类似于 Wed, 08 May 2013 11:11:30 GMT 的字符串。 (仅供引用,它是从 XML RSS 文件中提取的)我想要做的是从上面的字符串到两个变量,Wed, 08 May11:11 .据我所知,这里有几件事需要完成:

  • 删掉第三个空格之前的文字
  • 剪掉第4个空格和第2个冒号之间的文字
  • 将这两段文本保存为变量

除此之外,我不知道该怎么办。谁能帮忙?到目前为止,我的代码如下:

$.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 请求。

最佳答案

您的问题的解决方案位于:Parse RSS pubDate to Date object in JavaScript

为了同时获得时间:

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);

关于javascript - 将 RSS pubdate 字符串转换为 jQuery 中的时间和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16439977/

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