标签:tor mon == 情况 int [1] index 相互转换 substring
dateToString: function(date){ var year = date.getFullYear(); var month =(date.getMonth() + 1).toString(); var day = (date.getDate()).toString(); if (month.length == 1) { month = "0" + month; } if (day.length == 1) { day = "0" + day; } var dateTime = year + "-" + month + "-" + day; return dateTime; },
stringToDate : function(dateStr,separator){ if(!separator){ separator="-"; } var dateArr = dateStr.split(separator); var year = parseInt(dateArr[0]); var month; //处理月份为04这样的情况 if(dateArr[1].indexOf("0") == 0){ month = parseInt(dateArr[1].substring(1)); }else{ month = parseInt(dateArr[1]); } var day = parseInt(dateArr[2]); var date = new Date(year,month -1,day); return date; },
标签:tor mon == 情况 int [1] index 相互转换 substring
原文地址:https://www.cnblogs.com/houzheng/p/9007525.html