欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

查找当前日期所在周的周一的日期

程序员文章站 2022-07-15 12:52:29
...

JavaScript:

var now = new Date();
var monday = now;
monday.setDate(now.getDate() - now.getDay() + 1);
monday_date = monday.getFullYear() + "-" + monday.getMonth() + "-" + monday.getDate();

now = new Date();
var sunday = new Date();
sunday.setDate(now.getDate() - now.getDay() + 7);
monday_date = sunday.getFullYear() + "-" + sunday.getMonth() + "-" + sunday.getDate();

 Rails:

monday_date = Date.today.beginning_of_week.strftime('%d/%m/%Y')

 

相关标签: Rails Javascript