jQuery 日期时间选择器 - 设置开放日期和时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7523175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:58:07  来源:igfitidea点击:

Date Time Picker - Setting Opening Date and Time

jquerydatetimepicker

提问by Roger

I'm using this nifty little date and time picker [ http://trentrichardson.com/examples/timepicker/]. How can I set the date and time for when the picker opens?

我正在使用这个漂亮的小日期和时间选择器 [ http://trentrichardson.com/examples/timepicker/]。如何设置选择器打开的日期和时间?

回答by John Zumbrum

If you're using this on a form, set it from a hidden input.

如果您在表单上使用它,请从隐藏输入设置它。

$(document).ready(function () {
        $("#Date").datetimepicker({
            ampm: true
        });

        var date = new Date(
            Date.parse(
                $('#DatePicker').val(),
                "mm/dd/yyyy hh:MM tt"
            )
        );
        $('#Date').datetimepicker('setDate', date);
    });

HTML Form:

HTML 表单:

<input type="hidden" id="DatePicker" />
<input type="text" id="DatePicker" value="fromyourdatabase" />

回答by dinesh

Try this

$('#dtpkr').datetimepicker();

Then add

$('#dtpkr').datetimepicker('setDate', (new Date()));

This will give you the current date and time
尝试这个

$('#dtpkr').datetimepicker();

然后加

$('#dtpkr').datetimepicker('setDate', (new Date()));

这将为您提供当前日期和时间

回答by William Niu

You could pass a Dateobject to the setDatemethod.

您可以将Date对象传递给该setDate方法。

$('#datetimepicker').datetimepicker().click(function() {
    $(this).datetimepicker('setDate',new Date(2011, 11, 20, 8, 30));
});

See it in action: http://jsfiddle.net/william/Rkewu/1/.

看看它在行动:http: //jsfiddle.net/william/Rkewu/1/

回答by SpoiledTechie.com

Just focus it.

集中注意力就好。

$('#totTb').datetimepicker({
    timeFormat: 'HH:mm',
    timeSuffix: " Z"       
}).focus(function () { $('#totTb').datetimepicker('setDate', d) });

回答by Rusty Fausak

Try setting the valueattribute inside the inputelement like this:

尝试像这样设置元素value内的属性input

<input id="example1" value="05/05/2011" />