我使用此代码无需时间从文本中提取日期。是否有任何方法可以在没有时间的情况下提取日期,反之亦然?
$(document).on("change", "#select_date", function() {
const at = $('#select_date :selected').text()
//2016-03-26 15:22:02
const attend_date = at.substring(0,10)
});
答案 0 :(得分:4)
您可以按空格split()
日期并选择第一部分:
$(document).on("change", "#select_date", function() {
const at = $('#select_date :selected').text()
const attend_date = at.split(' ')[0]
})
答案 1 :(得分:0)
$(document).on("change", "#select_date", function() {
const at = $('#select_date :selected').text()
//extract date
const attend_date = at.split(' ')[0]
//extract time
const attend_time = at.split(' ')[1]
})