【发布时间】:2022-03-06 05:08:36
【问题描述】:
我有以下代码来显示日期和时间
**<div id='time'></div>
<script type="text/javascript">
// get a new date (locale machine date time)
var date = new Date();
// get the date as a string
var n = date.toDateString();
// get the time as a string
var time = date.toLocaleTimeString();
// find the html element with the id of time
// set the innerHTML of that element to the date a space the time
document.getElementById('time').innerHTML = n + ' ' + time;
</script>**
显示为 Wed Feb 09 2022 5:20:44 PM
我正在寻找的是如何让它显示为:
2 月 9 日,星期三,下午 5:20
感谢您的帮助
谢谢
【问题讨论】:
-
@user16320675 你是对的,我已经编辑了标题和标签 ;-)
-
这里是你要找的答案stackoverflow.com/a/14638191/9154326
标签: javascript date time