2017-01-30 44 views
0

我採取發佈日期但我需要更改日期類型。 現在,2017-01-19T14:02:39.000Z 但我想這種類型,19-01-2017, 我的代碼,採取發佈日期與youtube API v3

$.get(
 
\t "https://www.googleapis.com/youtube/v3/playlistItems",{ 
 
\t \t part : 'snippet', 
 
\t \t maxResults : 20, 
 
\t \t playlistId : pid, 
 
\t \t key : 'AIzaSyBZvGyNmLVPDLPcz_clh8tGxl0_1DRNFFE'}, 
 
\t \t function(data) { 
 
\t \t \t var output; 
 
\t \t \t $.each(data.items, function(i,item) { 
 
\t \t \t \t console.log(item); 
 
\t \t \t \t videoTitle = item.snippet.title; 
 
\t \t \t \t videoId = item.snippet.resourceId.videoId; 
 
\t \t \t \t videoDate = item.snippet.publishedAt; 
 
\t \t \t \t videoGorsel = item.snippet.thumbnails.default.url; 
 
\t \t \t \t height = item.snippet.thumbnails.default.height; 
 
\t \t \t \t width = item.snippet.thumbnails.default.width;

回答

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