function showDate(time){
        var date_obj = new Date(time),
            year,
            month,
            date;

        year = date_obj.getFullYear();
        month = String(date_obj.getMonth() + 1).length === 2 ? (date_obj.getMonth() + 1) : "0" + (date_obj.getMonth() + 1);
        date = String(date_obj.getDate()).length === 2 ? (date_obj.getDate()) : "0" + date_obj.getDate();
        return (year+"/"+month+"/"+date);
    }

1、今日:

showDate(Date.now())

生成“年-月-日”形式的日期字符串

2、本月1号:

showDate(Date.now()).replace(/\d{2}$/,"01")

生成“年-月-日”形式的日期字符串

3、一周前:

showDate(Date.now() - 7*24*3600*1000)

生成“年-月-日”形式的日期字符串

 

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-10-27
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案