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

前端 未结 15 1928
北海茫月
北海茫月 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:38

    Strongly inspired by @user2309185's.

    const ordinal = (d) => {
      return d + (['st', 'nd', 'rd'][d % 10 - 1] || 'th')
    }
    

提交回复
热议问题