请教大佬们jQuery如何实现获取当前日期?
目前需要实现以下图片日期格式,根据真实日期自动更新,请问如何实现
<div id="date">
<div id="date-month">October</div>
<div id="date-number">13</div>
<div id="date-weekday">FRIDAY</div>
</div>
回复
1个回答
test
2024-06-26
$(document).ready(function() {
var now = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekdays = ["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"];
// 获取当前月份、日期和星期
var month = months[now.getMonth()];
var date = now.getDate();
var weekday = weekdays[now.getDay()];
// 更新HTML元素的内容
$("#date-month").text(month);
$("#date-number").text(date);
$("#date-weekday").text(weekday);
});
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容