bootstrap 3 datepicker (eonasdan version) provides a datetime object with getDate(). not a string

只谈情不闲聊 提交于 2019-12-24 08:26:19

问题


I am using the following bootstrap 3 datepicker.

http://eonasdan.github.io/bootstrap-datetimepicker/

it works fine but there is an issue . during the change event
the output thrown out is a js object. i want a string. is taht possible.

there is another question asked along the same lines. but current version of datepicker has been updated and the old code does not run in jsfiddle.

html code is as follows:

<div class="form-group">
   <div class='input-group date' id='datetimepicker5' data-date-format="YYYY/MM/DD">
      <input type='text' class="form-control" />
         <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
                </span>
            </div>
</div>

my jquery code is as follows ;

$(function () {
            $('#datetimepicker5').datetimepicker({
                pickTime: false,
                useCurrent: true,
                showToday: true,
                language : 'en'
            });
$('#datetimepicker5').data('DateTimePicker').show();
});


//.... on change event

$('#datetimepicker5').on('dp.change', function() {
var t3= $('#datetimepicker5').data("DateTimePicker").getDate();
alert (t3.format('YYYY-MM-DD)); // this is the new change and works perfect 
});

any help is really appreciated


回答1:


If I interpret the installation instruction correctly, Eonasdan already has moment.js as a dependency. This answer from a related question provides some sample code on using moment.js to format a date in JavaScript.

If for some reason moment.js is not available, you can fall back to the native JavaScript functions. See this answer from the same question as I previously referred to.



来源:https://stackoverflow.com/questions/24852006/bootstrap-3-datepicker-eonasdan-version-provides-a-datetime-object-with-getdat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!