我想从wordpress rest api更改日期格式-我有以下代码:
<div class="post-item">
<div id="posts">Loading posts...</div>
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'https://mysite.io/blog/wp-json/wp/v2/posts?_embed&per_page=3',
success: function(data) {
var posts_html = '';
$.each(data, function(index, post) {
posts_html += '<div class="post-item-image">';
posts_html += '<a href="' + post.source_url + '"></a>';
posts_html += '<img src="' + +'"</div>';
posts_html += '<div class="post-item-header">';
posts_html += '<span class="date">' + post.date + '</span>';
posts_html += '<span class="user">';
posts_html += '<a href="' + post.link + '">';
posts_html += '<img src="https://mysite.io/images/users/mysite-1548344709.jpg">Mysites</a></span></div>';
posts_html += '<div class="post-item-body">';
posts_html += '<a href="' + post.link + '" style="text-decoration: underline;"> ' + post.title.rendered + '</a>';
posts_html += '<div class="post-short-text"> ' + post.excerpt.rendered + '</div></div>';
});
$('#posts').html(posts_html);
},
error: function(request, status, error) {
alert(error);
}
});
});
问题是我现在从以下位置获取此日期格式2019-05-20T19:15:42
posts_html += '<span class="date">' + post.date + '</span>';
我想将其更改为3 days ago
或确切日期20 May 2019
。有什么建议吗?