[英]How to get name of the day from date with momentjs
我正在使用momentjs
並想輸出當天的名稱,即。 “星期三”,但 API 似乎只提供了一個數字。
有沒有辦法在不將其硬編碼為特定語言的情況下做到這一點?
以防萬一,如果您想從索引日中獲取名稱
const day = 1; //second index after 0
moment().day(day).format("dddd") //Monday
使用moment().format('dddd');
獲得一天的全名,如 'Sunday' , 'Monday'
使用moment().format('ddd');
得到三個字母的名字,比如 'Sun' , 'Mon'
let day_name_full = moment().format('dddd'); let day_name_three_letter = moment().format('ddd'); console.log('== To Get Day Name =='); console.log("using format('dddd') =>",day_name_full); console.log("using format('ddd') =>",day_name_three_letter); console.log('== To Get Month Name =='); let month_name_full = moment().format('MMMM'); let month_name_three_letter = moment().format('MMM'); console.log("using format('MMMM') =>",month_name_full); console.log("using format('MMM') =>",month_name_three_letter);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.