js中字符串转换日期格式,日期转换字符串,操作日期(如:加一天)
1、字符串转换为date格式:
var isdate = new Date(strdate.replace(/-/g,"/"));
2、为date加一天:
var isdate = new Date((isdate/1000+86400)*1000);
//不能获取getDate()后再加,否则当日期到了31号时就会出现32号的情况。
3、date类型转换为string字符串类型:
var pdate = isdate.getFullYear()+"-"+(isdate.getMonth()+1)+"-"+(isdate.getDate());
说明:获取月份中,getMonth() 是从0开始的,所以要+1。
觉得可以,记得右上角点赞哦!如有不正确的地方,欢迎各位大神指教!
【The End】