如何使用javascript函数dateFormat几十年?

如何使用javascript函数dateFormat几十年?,javascript,date-format,Javascript,Date Format,如何使用Steven Levithan的dateFormat()函数将日期格式化为十年?我有个约会2019年5月9日下午5:46:21。我需要像“2010s”这样的东西。我应该为它创建一个新的掩码吗?有什么建议吗?我不熟悉Steven Levithan的dateFormat()函数,但您可以使用纯JS: 函数getDeced(日期){ 返回值(Math.floor(date.getFullYear()/10)*10)+s'; } var today=新日期(); var 90=新日期('199

如何使用Steven Levithan的dateFormat()函数将日期格式化为十年?我有个约会2019年5月9日下午5:46:21。我需要像“2010s”这样的东西。我应该为它创建一个新的掩码吗?有什么建议吗?

我不熟悉Steven Levithan的dateFormat()函数,但您可以使用纯JS:

函数getDeced(日期){ 返回值(Math.floor(date.getFullYear()/10)*10)+s'; } var today=新日期(); var 90=新日期('1995-12-15'); var独立日=新日期('1776-07-04'); console.log(getDecade(今天)); console.log(getDecade(九十年代));
console.log(GetTexage(independenceDay))谢谢。我只在原始函数中添加了一行。如果(掩码==“十年”)返回GetTexad(日期)@安德烈:太好了!如果此答案完全解决了您的问题,请考虑将其标记为已接受。