var dateTime=new Date();
dateTime=dateTime.setDate(dateTime.getDate()+18);
dateTime=new Date(dateTime);
console.log(dateTime);
console.log(dateTime.getMonth()+1);//月份需要加1
console.log(dateTime.getDate());
//当前日期加1天。 如果加30天。那么就跑到下面了。
注意使用数字parseInt。不然日期可能有错。
function show_huoqi(){
var huoqi = $("#huoqi").val();
huoqi = huoqi.replace(" ","");
//判断 货期必须是数字
var num_reg = /^[1-9]\d{0,5}$/;
if(num_reg.test(huoqi)){
}else{
$("#huoqi").val("");
$("#huoqi_date_text").html("");
return;
}
//判断 货期必须是数字
console.log(huoqi);
var dateTime=new Date();
dateTime=dateTime.setDate(dateTime.getDate()+parseInt(huoqi));
dateTime=new Date(dateTime);
console.log(dateTime.getFullYear()+"-"+(parseInt(dateTime.getMonth())+1)+"-"+dateTime.getDate());
//当前日期加1天。 如果加30天。那么就跑到下面了。
$("#huoqi_date_text").html("货期日期:"+dateTime.getFullYear()+"-"+(parseInt(dateTime.getMonth())+1)+"-"+dateTime.getDate());
}js输出当前日期
var date = new Date();
console.log(date);
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var seconds = date.getSeconds();
if(month>=1&&month<=9){
month="0"+month;
}
if(day>=1&&day<=9){
day = "0"+day;
}
if(hour>=1&&hour<=9){
hour = "0"+hour;
}
if(minute>=1&&minute<=9){
minute = "0"+minute;
}
if(seconds>=1&&seconds<=9){
seconds = "0"+seconds;
}
var time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds;
console.log(time);站长微信:xiaomao0055
站长QQ:14496453