[英]Moment.Js confusion for displaying the date
所以我目前正在為我的家庭作業使用 moment js,我必須在我們的日程安排的頂部顯示日期。 這就是我目前正在使用的
<body>
<header class="jumbotron">
<h1 class="display-3">Work Day Scheduler</h1>
<p class="lead">A simple calendar app for scheduling your work day</p>
<p id="currentDay" class="lead"></p>
</header>
在#currentDay 中,我需要顯示當前日期。 這就是我正在使用的
var currentDayDisplay = document.getElementById(currentDay);
moment(currentDayDisplay).format('MM/DD/YYYY');
這根本不起作用,知道為什么嗎?
你可以這樣做,
const currentDate = moment().format('MM/DD/YYYY'); // get current date document.getElementById("currentDay").textContent = currentDate; // display inside the element
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <p id="currentDay"></p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.