【发布时间】:2014-01-03 09:49:38
【问题描述】:
我正在使用 AJAX 从 XML 文件中获取数据并将其打印回给我。其中之一是日期,并使用以下代码:
jQuery(function(){
$.ajax({
url: 'http://www.sagittarius-digital.com/news.rss',
dataType: 'xml'
}).done(function(xml){
var items = $(xml).find('item').map(function(){
var $item = $(this);
var array = '<div class="item">';
array += '<p>' + $item.find('pubDate').text() + '</p>';
return array;
所以行:
array += '<p>' + $item.find('pubDate').text() + '</p>';
带回这样的日期:
Mon, 18 Nov 2013 12:00:00 GMT
如何将其转换为 YYYMMDD?不需要时间。
Live version in action(大车,加载需要一点时间)
【问题讨论】:
-
也许这个答案有帮助:stackoverflow.com/questions/18553936/…
-
你应该看看 moment.js,它是一个帮助你操作和格式化时间的库