bootstrap 3 datepicker(eonasdan版本)使用getDate()提供一个datetime对象。不是字符串 [英] bootstrap 3 datepicker (eonasdan version) provides a datetime object with getDate(). not a string

查看:272
本文介绍了bootstrap 3 datepicker(eonasdan版本)使用getDate()提供一个datetime对象。不是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下引导程序3 datepicker。



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



它工作正常但有问题。在更改事件期间

中抛出的输出是一个js对象。我想要一个字符串是可能的。



有另一个问题沿同一行提问。但是当前版本的datepicker已经更新,旧的代码不会在jsfiddle中运行。



html代码如下:

 < 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>

我的jquery代码如下;

  $(function(){
$('#datetimepicker5')。datetimepicker({
pickTime:false,
useCurrent:true,
(显示日期:true,
语言:'en'
});
$('#datetimepicker5')data('DateTimePicker')show();
} ;


//更改事件

$('#datetimepicker5')。on('dp.change',function(){
var t3 = $('#datetimepicker5')。data(DateTimePicker)。getDate();
alert(t3.format('YYYY-MM-DD)); //这是新的改变和工作完美
});

任何帮助非常感谢

解决方案

如果我解释安装说明正确地,Eonasdan已经有了moment.js作为依赖。 相关问题的此答案提供了一些使用moment.js的示例代码,以使用JavaScript格式化日期。



如果由于某种原因tim.js不可用,您可以回到本机JavaScript函数。请参阅这个答案与以前提到的相同的问题。


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

解决方案

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.

这篇关于bootstrap 3 datepicker(eonasdan版本)使用getDate()提供一个datetime对象。不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆