javascript date calculation example analysis

  • 2020-06-22 23:47:09
  • OfStack

This article is an example of javascript date calculation. Share to everybody for everybody reference. The details are as follows:


function setLeaveDate(){
  var inDay=$("#date_6").val();
  //  The date format is 2014-07-03
  var date=inDay.split('-');
  //  Divide the date into Numbers 
  var num=$(".time_lk").val()*1;
  //  Number of days to be added 
  var year=date[0]*1;
  var month=date[1]*1;
  var day=date[2]*1+num;
  var d = new Date(month+"/"+day+"/"+year);
  //  get 1 Date object , Pay attention to : Here the month corresponds to the calendar 
  var weekday=new Array(7);
  //  add 1 Parses the array displayed for weeks 
  weekday[0]=" Sunday ";
  weekday[1]=" weeks 1";
  weekday[2]=" weeks 2";
  weekday[3]=" weeks 3";
  weekday[4]=" weeks 4";
  weekday[5]=" weeks 5";
  weekday[6]=" weeks 6";
  month=d.getMonth()+1;
  //  Pay attention to : The months here still change , The index for months is 0~11,
  // So add here 1 It changes back to the month that corresponds to the calendar .
  result=month+" month "+d.getDate()+" day <br>"+weekday[d.getDay()]+" Your departure ";
  $(".time_2").text(result);
}

Hopefully, this article has been helpful in your javascript programming.


Related articles: