How to get the selected date value while using Bootstrap Datepicker?

前端 未结 12 898
有刺的猬
有刺的猬 2020-11-28 10:37

Using jquery and the Bootstrap Datepicker, how do I get the new date value I selected using the Bootstrap Datepicker? FYI, I\'m using Rails 3 and Coffescript.

I set

相关标签:
12条回答
  • 2020-11-28 10:56

    I was able to find the moment.js object for the selected date with the following:

    $('#datepicker').data('DateTimePicker').date()
    

    More info about moment.js and how to format the date using the moment.js object

    0 讨论(0)
  • 2020-11-28 11:03

    For bootstrap datepicker you can use:

    $("#inputWithDatePicer").data('datepicker').getFormattedDate('yyyy-mm-dd');
    
    0 讨论(0)
  • 2020-11-28 11:04

    this works with me for inline datepicker (and the other)

    $('#startdate').data('datepicker').date
    
    0 讨论(0)
  • 2020-11-28 11:06

    If you wan't the date in full text string format you can do it like this:

    $('#your-datepicker').data().datepicker.viewDate
    
    0 讨论(0)
  • 2020-11-28 11:07

    I tried with the above answers, but they didn't worked out for me; So as user3475960 referred, I used $('#startdate').html() which gave me the html text so i used it as necessary... May be some one will make use of it..

    0 讨论(0)
  • 2020-11-28 11:09

    Generally speaking,

    $('#startdate').data('date') 
    

    is best because

    $('#startdate').val()
    

    not work if you have a datepicker "inline"

    0 讨论(0)
提交回复
热议问题