Datetimepicker设置日期

Datetimepicker设置日期

本文介绍了Bootstrap Datetimepicker设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eonasdan的

我想使用 date 函数通过Javascript更新日期.我的尝试如下所示:

  $(#datetimepicker").data("DateTimePicker").date("2016-01-01"); 

不幸的是,这只会返回一个大对象,并且不会以任何方式更改可见日期.返回该对象

  Object {销毁:c/l.destroy(),切换:c/ha(),显示:c/ga(),隐藏:c/ba(),禁用:c/l.disable(),启用:c/l.enable(),ignoreReadonly:c/l.ignoreReadonly(),选项:c/l.options(),日期:c/l.date(),格式:c/l.format(),40 weitere…} 

使用其他时间格式或仅使用日期而不使用时间或其他任何方法也无济于事.

我在各种网站上找不到的建议解决方案都解决了我的问题.我不知道我是否必须更新元素?如果是这样,我该怎么办?我在文档中找不到任何提示...

使用defaultDate并不是一种选择,因为我需要在两个不同的日期执行两次此过程.

解决方案

根据文档您可以在下面使用 string,Date,moment,null ,string和Date示例.注意默认选择器格式.

  $('#datetimepicker1').data("DateTimePicker").date(new Date()) 

  $('#datetimepicker1').data("DateTimePicker").date('1/11/2016 12:23:12') 

I am using a datetimepicker from Eonasdan which works fine so far.

I have a HTML element like this

<div id="datetimepicker"></div>

and use the datetimepicker function like this:

$("#datetimepicker").datetimepicker({
    inline: true,
    sideBySide: true,
    stepping: 5,
    locale: "de"
});

The result looks like this:

I want to update the date via Javascript using the date function. My try looks like this:

$("#datetimepicker").data("DateTimePicker").date("2016-01-01");

Unfortunately this only returns a large object and does not alter the visible date in any way. This object is returned

Object { destroy: c/l.destroy(), toggle: c/ha(), show: c/ga(), hide: c/ba(),
    disable: c/l.disable(), enable: c/l.enable(), ignoreReadonly: c/l.ignoreReadonly(),
    options: c/l.options(), date: c/l.date(), format: c/l.format(), 40 weitere… }

Using a different time format or taking only date and no time or whatsoever does not help either.

None of the suggested solutions I found on various websites have solved my problem. I don't know whether I have to update the element? If so, how do I do it? I could not find any hint in the docs...

It is not an option to use the defaultDate since I need to do this process twice with two different dates.

解决方案

As per documentation you can use string, Date, moment, null, string and Date examples are below. Note default picker format.

$('#datetimepicker1').data("DateTimePicker").date(new Date())

or

$('#datetimepicker1').data("DateTimePicker").date('1/11/2016 12:23:12')

这篇关于Bootstrap Datetimepicker设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:13