我采取发布日期,但需要更改日期类型。 现在,2017-01-19T14:02:39.000Z 但我想要这种类型,19-01-2017, 我的代码,
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems",{
part : 'snippet',
maxResults : 20,
playlistId : pid,
key : 'AIzaSyBZvGyNmLVPDLPcz_clh8tGxl0_1DRNFFE'},
function(data) {
var output;
$.each(data.items, function(i,item) {
console.log(item);
videoTitle = item.snippet.title;
videoId = item.snippet.resourceId.videoId;
videoDate = item.snippet.publishedAt;
videoGorsel = item.snippet.thumbnails.default.url;
height = item.snippet.thumbnails.default.height;
width = item.snippet.thumbnails.default.width;
答案 0 :(得分:0)
假设您已经解析了响应并获得了日期值2017-01-19T14:02:39.000Z,这里是如何做到的。 使用Date methods from W3 Schools:
var isODate = new Date("2017-01-19T14:02:39.000Z");
var shortDate = new Date(isODate);
var day = shortDate.getDate();
var month = shortDate.getMonth() + 1;
var year = shortDate.getFullYear();
var stringdate = day+"-"+month+"-"+year;
console.log(stringdate);
输出:19-1-2017