gpt4 book ai didi

JavaScript pubDate RSS 格式

转载 作者:行者123 更新时间:2023-11-28 10:22:25 24 4
gpt4 key购买 nike

我有一个使用 javascript 创建的 RSS 提要阅读器,需要格式化日期。目前 pubDate 设置为 .toLocaleDateString 并且在不同的机器上显示不同。

有人知道我是否可以将其设置为标准 dd/mm/yyyy 格式吗?

下面是完整的 JavaScript:

    (function ($) {
var current = null;
$.fn.rssfeed = function (url, options) {
var defaults = {
limit: 10,
header: true,
titletag: 'h4',
date: true,
content: true,
snippet: true,
showerror: true,
errormsg: '',
key: null
};
var options = $.extend(defaults, options);
return this.each(function (i, e) {
var $e = $(e);
if (!$e.hasClass('rssFeed')) $e.addClass('rssFeed');
if (url == null) return false;
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + url;
if (options.limit != null) api += "&num=" + options.limit;
if (options.key != null) api += "&key=" + options.key;
$.getJSON(api, function (data) {
if (data.responseStatus == 200) {
_callback(e, data.responseData.feed, options);
} else {
if (options.showerror) if (options.errormsg != '') {
var msg = options.errormsg;
} else {
var msg = data.responseDetails;
};
$(e).html('<div class="rssError"><p>' + msg + '</p></div>');
};
});
});
};
var _callback = function (e, feeds, options) {
if (!feeds) {
return false;
}
var html = '';
var row = 'odd';
if (options.header) html += '';
html += '<div class="rssBody">' + '<ul>';
for (var i = 0; i < feeds.entries.length; i++) {
var entry = feeds.entries[i];
var entryDate = new Date(entry.publishedDate);
var pubDate = entryDate.toLocaleDateString() + ' ' + entryDate.toLocaleTimeString();
html += '<li class="rssRow ' + row + '">' + '<' + options.titletag + '><a href="' + entry.link + '" title="View this feed at ' + feeds.title + '" class="blog">' + entry.title + '</a></' + options.titletag + '>'
if (options.date) html += '<p class="date">' + pubDate + '</p>'
if (options.content) {
if (options.snippet && entry.contentSnippet != '') {
var content = entry.contentSnippet;
} else {
var content = entry.content;
}
html += '<p>' + content + '</p><p><a href="' + entry.link + '" class="blogbtn">continue reading</a></p>'
}
html += '</li>';
if (row == 'odd') {
row = 'even';
} else {
row = 'odd';
}
}
html += '</ul>' + '</div>'
$(e).html(html);
};
})(jQuery);

最佳答案

你可以做到

var pubDate = entryDate.format("dd/mm/yyyy");

关于JavaScript pubDate RSS 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282812/

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