1. 程式人生 > >21-js 實現評論時間格式轉化

21-js 實現評論時間格式轉化

  js裡面要用可以用伊爾表示式,迴圈是用js:

document.getElementById("${pj.pltime }").innerHTML = dateToGMT("${pj.pltime }");

        <div class="order-info">
		<p id="${pj.pltime}">
			<script type="text/javascript">
				function dateToGMT(strDate) {
					console.log("原始時間格式:" + strDate);
					var date = new Date(strDate);
					var y = date.getFullYear();
					var m = date.getMonth() + 1;
					m = m < 10 ? ('0' + m) : m;
					var d = date.getDate();
					d = d < 10 ? ('0' + d) : d;
					var h = date.getHours();
					var minute = date.getMinutes();
					minute = minute < 10 ? ('0' + minute) : minute;
					var str = y + "-" + m + "-" + d + " " + h + ":" + minute;
					console.log("轉換時間格式:" + str);
					return "評論時間:" + str;
				}
				document.getElementById("${pj.pltime }").innerHTML = dateToGMT("${pj.pltime }");
			</script>
		</p>

	</div>