JavaScript new Date Ordinal (st, nd, rd, th)

前端 未结 15 1926
北海茫月
北海茫月 2020-11-27 03:12

If at all possible, without JavaScript libraries or lots of clunky code I am looking for the simplest way to format a date two weeks from now in the following format:

<
15条回答
  •  渐次进展
    2020-11-27 03:49

    One more solution in the sea of solutions.

    let suffix = (day >= 4 &&  day <= 20) || (day >= 24 && day <= 30)
        ? "th"
        : ["st", "nd", "rd"][day % 10 - 1];
    

提交回复
热议问题