【问题标题】:Take published Date with youtube api v3使用 youtube api v3 获取发布日期
【发布时间】:2017-06-15 14:15:46
【问题描述】:

我选择发布日期,但我需要更改日期类型。 现在,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;

【问题讨论】:

    标签: javascript api youtube-api


    【解决方案1】:

    假设您已经解析了响应并获得了日期值 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-11
      • 2015-08-29
      • 1970-01-01
      • 2015-12-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      相关资源
      最近更新 更多