Extract date from text

2019-09-12 21:08发布

I'm using this code to extract date from text without time. Is there any method to extract date without time and vice versa?

$(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)
});

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-12 21:41
$(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]
})
查看更多
三岁会撩人
3楼-- · 2019-09-12 22:08

You can split() the date by space and select the first part:

$(document).on("change", "#select_date", function() {
  const at = $('#select_date :selected').text()
  const attend_date = at.split(' ')[0]
})
查看更多
登录 后发表回答