切割字符串再拼接过滤日期格式

后台传来的日期格式是2019-3-3形式没有0,用户选择的格式是2019-03-03,需要把0过滤掉。

 

					var test1 = $('#test1').val(); //获取到用户输入日期的值
					console.log("需要查询的日期:" + test1);
					var test1 = $('#test1').val().split(""); //先把日期分割成单个字符
					if (test1[5] == "0" && test1[8] == "0") {
						console.log("月份与天数的首位均为0");
						test1.splice(5, 1);
						test1.splice(7, 1);
						test1 = test1[0] + test1[1] + test1[2] + test1[3] + test1[4] + test1[5] + test1[6] + test1[7];
						console.log("去掉0后需要查询的日期:" + test1);
					} else if (test1[5] == "0" && test1[8] != "0") {
						console.log("月份首位为0");
						test1.splice(5, 1);
						test1 = test1[0] + test1[1] + test1[2] + test1[3] + test1[4] + test1[5] + test1[6] + test1[7] + test1[8];
						console.log("去掉0后需要查询的日期:" + test1);
					} else if (test1[5] != "0" && test1[8] == "0") {
						console.log("天数首位为0");
						test1.splice(8, 1);
						test1 = test1[0] + test1[1] + test1[2] + test1[3] + test1[4] + test1[5] + test1[6] + test1[7] + test1[8];
						console.log("去掉0后需要查询的日期:" + test1);
					}

 

posted @ 2019-04-11 18:04  neverthelessing  阅读(41)  评论(0)    收藏  举报