Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中获取当前日期?(How do I get the current date in JavaScript?)

如何在JavaScript中获取当前日期?

  ask by Suresh Chaganti translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.(您想要的任何格式。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...