js 日付 整形

var weeks = ['日', '月', '火', '水', '木', '金', '土'];
function dateFormat(date){
	var dateStr = new Date(date);
	var year = dateStr.getFullYear();
	var month = dateStr.getMonth() + 1;
	var day = dateStr.getDate();
	var week = dateStr.getDay();
	var hour = ('0' + dateStr.getHours()).slice(-2);
	var minute = ('0' + dateStr.getMinutes()).slice(-2);
	var second = ('0' + dateStr.getSeconds()).slice(-2);
	return year + '/' + month + '/' + day + '(' + weeks[week] + ') ' + hour + ':' + minute + ':' + second;
}

var pubDate = 'Wed, 05 Jul 2017 15:00:00 +0900';
// 整形
pubDate = dateFormat(pubDate);
// 文字列をノードに変換
pubDate = document.createTextNode(pubDate);
// 読み込み順序の調整
window.onload = function(){
	document.getElementById('output').appendChild(pubDate);
}
<div id="output"></div>
2017/7/5(水) 15:00:00
PAGE TOP