码迷,mamicode.com
首页 > 其他好文 > 详细

根据系统当前日期获取上周时间段

时间:2017-10-20 18:40:53      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:attr   date   取值   get   时间段   tar   标签   format   格式化   

//获取系统当前时间
var now = new Date(); //当前日期
var nowDayOfWeek = now.getDay(); //今天本周的第几天
var nowDay = now.getDate(); //当前日
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getYear(); //当前年
nowYear += (nowYear < 2000) ? 1900 : 0; //
//格式化日期:yyyy-MM-dd
function formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth()+1;
var myweekday = date.getDate();

if(mymonth < 10){
mymonth = "0" + mymonth;
}
if(myweekday < 10){
myweekday = "0" + myweekday;
}
return (myyear+"-"+mymonth + "-" + myweekday);
}

//获取上周时间
$(function(){
$(".upWeek").click(function(){

$(".downWeek").removeAttr(‘disabled‘)
$(".downWeek").css("background-color", "#3389E4")
//获取值
var getUpWeekStartDate_1 = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek -6);

//给获取到的值进行格式化
var getUpWeekStartDate_1 = formatDate(getUpWeekStartDate_1);

//给value赋值
//星期一上午
$(".time_0").val(getUpWeekStartDate_1);

//禁用上周标签
$(".upWeek").attr("disabled", true)
$(".upWeek").css("background-color", "Gray")

})
})

根据系统当前日期获取上周时间段

标签:attr   date   取值   get   时间段   tar   标签   format   格式化   

原文地址:http://www.cnblogs.com/yhyl/p/7700162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!