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

JavaScript:

Js代码 
  1. var now = new Date();  
  2. var monday = now;  
  3. monday.setDate(now.getDate() - now.getDay() + 1);  
  4. monday_date = monday.getFullYear() + "-" + monday.getMonth() + "-" + monday.getDate();  
  5.   
  6. now = new Date();  
  7. var sunday = new Date();  
  8. sunday.setDate(now.getDate() - now.getDay() + 7);  
  9. monday_date = sunday.getFullYear() + "-" + sunday.getMonth() + "-" + sunday.getDate();  

 Rails:

Ruby代码 
  1. monday_date = Date.today.beginning_of_week.strftime('%d/%m/%Y')  

猜你喜欢

转载自wudixiaotie.iteye.com/blog/2033585
今日推荐