split
// 和数组的join方法相对应(join->按照指定的分隔符把数组拆分成字符串)
// 把一个字符串按照指定的分隔符,拆分成数组中的每一项
// var ary = [12, 23, 34, 45];
// var str = ary.join("+");
// console.log(str);//->"12+23+34+45"
// var newAry = str.split("+");
// console.log(newAry);//->["12", "23", "34", "45"]
var str = "2016-1-2 13:1:23";
//->"2016年01月02日 13时01分23秒"
var ary = str.split(" ");//->["2016-1-2", "13:1:23"]
var leftAry = ary[0].split("-");//->"2016-1-2" ->["2016", "1", "2"]
var rightAry = ary[1].split(":");//->"13:1:23" ->["13", "1", "23"]
var time = leftAry[0] + "年" + addZero(leftAry[1]) + "月" + addZero(leftAry[2]) + "日 " + addZero(rightAry[0]) + "时" + addZero(rightAry[1]) + "分" + addZero(rightAry[2]) + "秒";
console.log(time);
function addZero(value) {
if (value < 10) {
value = "0" + value;
}
return value;
// return value < 10 ? "0" + value : value;
}