数组字符串的
时间
转换成固定格式(时分)
let time = ["08:00:00-09:00:00", "10:00:00-12:00:00", "10:00:00-12:00:00"]
function decomposeTime(time,frm="-") {
let obj = []
time.map((item, index) => {
let _item = item.substring(0, 5) + item.substring(8, 14)
obj.push({
id: +new Date(),
start: _item.split(frm)[0],
end: _item.split(frm)[1]
})
})
return obj
}
转换的时间再转换回去
function composeTime(obj) {
let data = '';
obj.forEach(item => {
data += ","+item.start + ":00-" + item.end + ':00'
})
return data.substr(1)
}
结果:
let data = decomposeTime(time)
console.log(data)
console.log(composeTime(data))