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
539 views
in Technique[技术] by (71.8m points)

javascript - 如何在Javascript中获取当前格式化的日期dd / mm / yyyy并将其附加到输入[duplicate](How to get current formatted date dd/mm/yyyy in Javascript and append it to an input [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

I would like to add a current date to a hidden HTML tag so that it can be sent to the server:

(我想在隐藏的HTML标记中添加当前日期,以便将其发送到服务器:)

<input type="hidden" id="DATE" name="DATE" value="WOULD_LIKE_TO_ADD_DATE_HERE">

How can I add a formatted date to the VALUE attribute?

(如何在VALUE属性中添加格式化日期?)

  ask by VolosBlur translate from so

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

1 Answer

0 votes
by (71.8m points)

I hope this is what you want:

(我希望这是你想要的:)

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!

var yyyy = today.getFullYear();
if (dd < 10) {
  dd = '0' + dd;
} 
if (mm < 10) {
  mm = '0' + mm;
} 
var today = dd + '/' + mm + '/' + yyyy;
document.getElementById('DATE').value = today;

How do I get the current date in JavaScript?

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


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

...