Use new Date()
to generate a new Date
object containing the current date and time.(使用new Date()
生成一个包含当前日期和时间的新Date
对象。)
var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; document.write(today);
This will give you today's date in the format of mm/dd/yyyy.(这将以mm / dd / yyyy的格式给您今天的日期。)
Simply change today = mm +'/'+ dd +'/'+ yyyy;
(today = mm +'/'+ dd +'/'+ yyyy;
只需更改today = mm +'/'+ dd +'/'+ yyyy;
) to whatever format you wish.(您想要的任何格式。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…