Home  >  Article  >  Web Front-end  >  JavaScript date calculation example analysis_javascript skills

JavaScript date calculation example analysis_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:52:211255browse

The examples in this article describe javascript date calculation. Share it with everyone for your reference. The details are as follows:

function setLeaveDate(){
  var inDay=$("#date_6").val();
  // 获取的日期格式为2014-07-03
  var date=inDay.split('-');
  // 将日期分隔成数字
  var num=$(".time_lk").val()*1;
  // 需增加的天数
  var year=date[0]*1;
  var month=date[1]*1;
  var day=date[2]*1+num;
  var d = new Date(month+"/"+day+"/"+year);
  // 得到一个日期对象,注意:这里的月与日历是对应的
  var weekday=new Array(7);
  // 添加一个解析星期显示的数组
  weekday[0]="周日";
  weekday[1]="周一";
  weekday[2]="周二";
  weekday[3]="周三";
  weekday[4]="周四";
  weekday[5]="周五";
  weekday[6]="周六";
  month=d.getMonth()+1;
  // 注意:这里的月份依然变了,月份的索引为0~11,
  //故此在此处加1才会变回与日历对应的月份.
  result=month+"月"+d.getDate()+"日<br>"+weekday[d.getDay()]+"离店";
  $(".time_2").text(result);
}

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn