我檢查了與此類似的其他帖子,但沒有得到我需要的答案。將st,th,rd添加到jQuery日期
如何將這些單詞添加到我的數字末尾?
,這裏是我的jQuery代碼:
var monthNames = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
var dayNames= ["Sunday,","Monday,","Tuesday,","Wednesday,","Thursday,","Friday,","Saturday,"]
var newDate = new Date();
newDate.setDate(newDate.getDate());
$('#the-date').html(dayNames[newDate.getDay()] + " " + monthNames[newDate.getMonth()] + ' ' + newDate.getDate() + ' ');
你看到[這個問題和它的接受的答案](https://stackoverflow.com /問題/ 13627308 /添加-ST-ND-RD-和-TH-序後綴到一個數)?這似乎正是你需要的。 –
我做了但不知道哪一個我應該使用.. – Chad
雖然這[功能](https://ecommerce.shopify.com/c/ecommerce-design/t/ordinal-number-in-javascript-1st-2nd- 3rd-4th-29259)從其中一個答案看起來相當不錯 –