<div id="time"></div> <script type="text/javascript"> // 将日期格式化输出 2015|08|24 function formatter(s) { var oDate = new Date(); //获取当前时间 Sun Nov 08 2020 22:29:47 GMT+0800 (中国标准时间) var year = oDate.getFullYear(); //获取当前年份 var month = oDate.getMonth() + 1; //获取当前月份 月份从0开始,11表示12月,要加1 var date = oDate.getDate(); // 获取当月几号 month = month < 10 ? month : month; date = date < 10 ? "0" + date : date; var time = year + s + month + s + date; return time; } var t = formatter("|"); var oDiv = document.getElementById("time"); oDiv.innerHTML = t; </script>
<div id="time"></div>
<script type="text/javascript">
// 将日期格式化输出 2015|08|24
function formatter(s) {
var oDate = new Date(); //获取当前时间 Sun Nov 08 2020 22:29:47 GMT+0800 (中国标准时间)
var year = oDate.getFullYear(); //获取当前年份
var month = oDate.getMonth() + 1; //获取当前月份 月份从0开始
var date = oDate.getDate(); // 获取当月几号
month = month < 10 ? month : month;
date = date < 10 ? "0" + date : date;
var time = year + s + month + s + date;
return time;
}
var t = formatter("|");
var oDiv = document.getElementById("time");
oDiv.innerHTML = t;
</script>