jQuery 日期/时间选择器

发布于 2024-07-30 08:50:44 字数 210 浏览 15 评论 0 原文

我一直在寻找一个像样的 jQuery 插件,可以处理日期和时间。 核心 UI DatePicker 很棒,但不幸的是我也需要花时间。

我发现了一些让 DatePicker 与时间一起工作的技巧,但它们看起来都很不优雅,谷歌也没有发现任何好的东西。

是否有一个好的 jQuery 插件可以在具有可用界面的单个 UI 控件中选择日期和时间?

I've been looking around for a decent jQuery plugin that can handle both dates and times. The core UI DatePicker is great, but unfortunately I need to be able to take time in as well.

I've found a few hacks for the DatePicker to work with times, but they all seem pretty inelegant and Google isn't turning up anything nice.

Is there a good jQuery plugin for selecting dates and times in a single UI control with a usable interface?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

爱*していゐ 2024-08-06 08:50:45

只是为了在这里添加信息,Fluid Project 有一篇很好的 wiki 文章,概述了大量日期和/或时间选择器 此处

Just to add to the info here, The Fluid Project has a nice wiki write-up overviewing a large number of date and/or time pickers here.

静谧幽蓝 2024-08-06 08:50:45

我最近对此进行了研究,但尚未找到一个像样的日期选择器,其中还包括一个像样的时间选择器。 我最终使用的是 eyecon 很棒的 DatePicker,有两个简单的时间下拉菜单。 我很想使用 Timepickr.js 不过,看起来非常不错方法。

I researched this just recently and have yet to find a decent date picker that also includes a decent time picker. What I ended up using was eyecon's awesome DatePicker, with two simple dropdowns for time. I was tempted to use Timepickr.js though, looks like a really nice approach.

想你只要分分秒秒 2024-08-06 08:50:45

我遇到了同样的问题。 我实际上是使用服务器端编程开发的,但我进行了快速搜索以尝试帮助您并找到了这个。

看起来还不错,没有太多看源代码,但似乎是纯粹的 JavaScript。

看一下:

http://www.rainforestnet.com/datetimepicker/datetimepicker.htm

这是演示页面链接:

http://www.rainforestnet.com/datetimepicker/datetimepicker -demo.htm

祝你好运

I have ran into that same problem. I actually developed my using server side programming, but I did a quick search to try and help you out and found this.

Seems alright, didn't look at the source too much, but seems to be purely JavaScript.

Take look:

http://www.rainforestnet.com/datetimepicker/datetimepicker.htm

Here is the demo page link:

http://www.rainforestnet.com/datetimepicker/datetimepicker-demo.htm

good luck

凉城已无爱 2024-08-06 08:50:45

这是我用来让用户选择一个的代码
datetimepicker,设置日期时间,并有
其他日期时间选择器向该时间添加一分钟。

我需要这个来进行定制药物控制......

无论如何,我认为它可能会帮助其他人,因为我可以
在网上找不到答案...

(至少不是完整的答案)

请记住,添加的 60000 会增加一分钟。
(60 * 1000 毫秒)

$('.frdtPicker').datetimepicker({
        onClose: function(dateText, inst) {
            var endDateTextBox = $('.todtPicker');
            if (endDateTextBox.val() != '') {
                var testStartDate = new Date(dateText);
                var testEndDate = new Date(endDateTextBox.val());
                if (testStartDate > testEndDate) {

                    var testStartDate = new Date(dateText).getTime() + 60000;
                    var testStartDate2 = new Date(testStartDate); 

                    endDateTextBox.datetimepicker('setDate', (new Date(testStartDate2)));
                }
            }
            else {
                var testStartDate = new Date(dateText).getTime() + 60000;
                var testStartDate2 = new Date(testStartDate);
                endDateTextBox.datetimepicker('setDate', (new Date(testStartDate2)));
            }
            $('.frdtPicker').val(dateText); //endDateTextBox.val());

        },
        onSelect: function(selectedDateTime) {
            var start = $(this).datetimepicker('getDate');
            $('.todtPicker').datetimepicker('option', 'minDate', new Date(start.getTime()));
        }
    });

This is some code I use to have a user select one
datetimepicker, set the datetime, and have the
other datetimepicker add One Minute to that time.

I needed this for a custom medication control....

Anyway, thought it might help someone else since I could
not find the answer any where online...

(at least not a complete answer)

Keep in mind that the 60000 added, adds one minute.
(60 * 1000 milliseconds)

$('.frdtPicker').datetimepicker({
        onClose: function(dateText, inst) {
            var endDateTextBox = $('.todtPicker');
            if (endDateTextBox.val() != '') {
                var testStartDate = new Date(dateText);
                var testEndDate = new Date(endDateTextBox.val());
                if (testStartDate > testEndDate) {

                    var testStartDate = new Date(dateText).getTime() + 60000;
                    var testStartDate2 = new Date(testStartDate); 

                    endDateTextBox.datetimepicker('setDate', (new Date(testStartDate2)));
                }
            }
            else {
                var testStartDate = new Date(dateText).getTime() + 60000;
                var testStartDate2 = new Date(testStartDate);
                endDateTextBox.datetimepicker('setDate', (new Date(testStartDate2)));
            }
            $('.frdtPicker').val(dateText); //endDateTextBox.val());

        },
        onSelect: function(selectedDateTime) {
            var start = $(this).datetimepicker('getDate');
            $('.todtPicker').datetimepicker('option', 'minDate', new Date(start.getTime()));
        }
    });
寒冷纷飞旳雪 2024-08-06 08:50:45

看看下面的 JavaScript 插件。

带有日期和时间的 Javascript 日历

我已使其尽可能简单。 但它仍处于早期阶段。
让我知道反馈,以便我可以改进它。

Take a look at the following JavaScript plugin.

Javascript Calendar with date and time

I've made it to be simple as possible. but it still in its early days.
Let me know the feedback so I could improve it.

千里故人稀 2024-08-06 08:50:45

不是 jQuery,但它非常适合带有时间的日历:JavaScript 日期时间选择器< /em>.

我只是绑定了点击事件来弹出它:

$(".arrival-date").click(function() {
    NewCssCal($(this).attr('id'), 'mmddyyyy', 'dropdown', true, 12);
});

Not jQuery, but it works well for a calendar with time: JavaScript Date Time Picker.

I just bound the click event to pop it up:

$(".arrival-date").click(function() {
    NewCssCal($(this).attr('id'), 'mmddyyyy', 'dropdown', true, 12);
});
香橙ぽ 2024-08-06 08:50:45

我做了一个这样的函数:

function getTime()
{
    var date_obj = new Date();
    var date_obj_hours = date_obj.getHours();
    var date_obj_mins = date_obj.getMinutes();
    var date_obj_second = date_obj.getSeconds();

    var date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+":"+date_obj_second+"'";
    return date_obj_time;
}

然后我像这样使用 jQuery UI 日期选择器:

$("#selector").datepicker( "option", "dateFormat", "yy-mm-dd "+getTime()+"" );

所以,我得到这样的值: 2010-10-31 12:41:57

I make one function like this:

function getTime()
{
    var date_obj = new Date();
    var date_obj_hours = date_obj.getHours();
    var date_obj_mins = date_obj.getMinutes();
    var date_obj_second = date_obj.getSeconds();

    var date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+":"+date_obj_second+"'";
    return date_obj_time;
}

Then I use the jQuery UI datepicker like this:

$("#selector").datepicker( "option", "dateFormat", "yy-mm-dd "+getTime()+"" );

So, I get the value like this: 2010-10-31 12:41:57

假扮的天使 2024-08-06 08:50:45

我们很难找到一个能按照我们想要的方式工作的方法,所以我写了一个。 我维护源代码并修复出现的错误并提供免费支持。

http://www.yart。 com.au/Resources/Programming/ASP-NET-JQuery-Date-Time-Control.aspx

We had trouble finding one that worked the way we wanted it to so I wrote one. I maintain the source and fix bugs as they arise plus provide free support.

http://www.yart.com.au/Resources/Programming/ASP-NET-JQuery-Date-Time-Control.aspx

樱花落人离去 2024-08-06 08:50:44

到目前为止,最好、最简单的日期时间选择器选项是 http://trentrichardson.com/examples/timepicker/

它是 jQuery UI Datepicker 的扩展,因此它也支持相同的主题,并且工作方式非常相同,语法相似等。在我看来,这应该与 jQuery UI 打包在一起。

By far the nicest and simplest DateTime picker option is http://trentrichardson.com/examples/timepicker/.

It is an extension of the jQuery UI Datepicker so it will support the same themes as well it works very much the same way, similar syntax, etc. This should be packaged with the jQuery UI imo.

不即不离 2024-08-06 08:50:44

@David,感谢您的推荐! @fluid_chelsea,我刚刚发布了 Any+Time(TM) 版本 3.x,它使用 jQuery 而不是 Prototype,并且具有大大改进的界面,所以我希望它现在满足您的需求:

http://www.ama3.com/anytime/

如有任何问题,请通过我网站上的评论链接告诉我!

@David, thanks for the recommendation! @fluid_chelsea, I've just released Any+Time(TM) version 3.x which uses jQuery instead of Prototype and has a much-improved interface, so I hope it now meets your needs:

http://www.ama3.com/anytime/

Any problems, please let me know via the comment link on my website!

绝不放开 2024-08-06 08:50:44

在我看来,日期和时间应作为两个单独的输入框处理,以便用户输入最有用且最高效。 让用户一次输入一件事是一个很好的原则,恕我直言。

我使用核心 UI DatePicker 和以下时间选择器。

这个的灵感来自于 Google 日历使用的一个:

jQuery timePicker
示例: http://labs.perifer.se/timedatepicker/
github上的项目: https://github.com/perifer/timePicker

我发现它是最好的在所有替代方案中。 用户可以快速输入,它看起来干净、简单,并且允许用户输入精确到分钟的特定时间。

附:
在我看来:滑块(由一些替代时间选择器使用)需要过多的点击,并且需要用户的鼠标精度(这使得输入速度变慢)。

In my view, dates and times should be handled as two separate input boxes for it to be most usable and efficient for the user to input. Let the user input one thing at a time is a good principle, imho.

I use the core UI DatePicker, and the following time picker.

This one is inspired by the one Google Calendar uses:

jQuery timePicker:
examples: http://labs.perifer.se/timedatepicker/
project on github: https://github.com/perifer/timePicker

I found it to be the best among all of the alternatives. User can input fast, it looks clean, is simple, and allows user to input specific times down to the minute.

PS:
In my view: sliders (used by some alternative time pickers) take too many clicks and require mouse precision from the user (which makes input slower).

℉絮湮 2024-08-06 08:50:44

我对日期选择器的最佳体验是基于原型的 AnyTime。 我知道这不是 jQuery,但它可能仍然值得您做出妥协。 我完全不知道原型,但它仍然很容易使用。

我发现一个警告:它在某些浏览器上不向前兼容。 也就是说,它不适用于 Chrome 上较新版本的原型。

My best experience with a datepicker is with the prototype-based AnyTime. I know that's not jQuery, but it may still be worth the compromise for you. I know absolutely no prototype, and it's still easy enough to work with.

One caveat I've found: it is not forward compatible on some browsers. That is, it did not work with a newer version of prototype on Chrome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文