本人在网上查找的,  觉得还不错,就抄过来了... 有错误大家一起讨论,谢谢...

原地址是:http://www.bootcss.com/p/bootstrap-datetimepicker/

项目 

此项目是bootstrap-datetimepicker 项目 的一个分支,原项目不支持 Time 选择。
其它部分也进行了改进、增强,例如load 过程增加了对 ISO-8601 日期格式的支持。
文档是拷贝/粘贴字原项目的文档,并且加入了更多细节说明。
 
别犹豫了,下载下来试试吧 !
此地址可以克隆或fork本项目
  1. git clone git://github.com/smalot/bootstrap-datetimepicker.git

希望这个小小的项目能帮到你 !

Tags: twitter-bootstrapdatetimepickercomponentjavascriptwidget

截图

十年视图

年视图

月视图

日视图*

小时视图 *

Day view w/ meridian *

Hour view w/ meridian *

(*) Added views to select the time part.

依赖

需要bootstrap的下拉菜单组件 (dropdowns.less) 的某些样式,还有bootstrap的sprites (sprites.less and associated images) 中的箭头图标。

A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by runningbuild/build_standalone.less through the lessc compiler:

  1. $ lessc build/build_standalone.less datetimepicker.css

选项

所有需要"Date" 的选项都可以处理Date 对象; a String formatted according to the given format; or a timedelta relative to today, eg '-1d', '+6m +1y', etc, where valid units are 'd' (day), 'w' (week), 'm' (month), and 'y' (year).

你也可以指定一个符合 ISO-8601 格式的日期时间,就可以忽略下面的格式:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:ii
  • yyyy-mm-ddThh:ii
  • yyyy-mm-dd hh:ii:ss
  • yyyy-mm-ddThh:ii:ssZ

format

String. 默认值: 'mm/dd/yyyy'

日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。

  • p : meridian in lower case ('am' or 'pm') - according to locale file
  • P : meridian in upper case ('AM' or 'PM') - according to locale file
  • s : seconds without leading zeros
  • ss : seconds, 2 digits with leading zeros
  • i : minutes without leading zeros
  • ii : minutes, 2 digits with leading zeros
  • h : hour without leading zeros - 24-hour format
  • hh : hour, 2 digits with leading zeros - 24-hour format
  • H : hour without leading zeros - 12-hour format
  • HH : hour, 2 digits with leading zeros - 12-hour format
  • d : day of the month without leading zeros
  • dd : day of the month, 2 digits with leading zeros
  • m : numeric representation of month without leading zeros
  • mm : numeric representation of the month, 2 digits with leading zeros
  • M : short textual representation of a month, three letters
  • MM : full textual representation of a month, such as January or March
  • yy : two digit representation of a year
  • yyyy : full numeric representation of a year, 4 digits

weekStart

Integer. 默认值:0

一周从哪一天开始。0(星期日)到6(星期六)

startDate

Date. 默认值:开始时间

The earliest date that may be selected; all earlier dates will be disabled.

endDate

Date. 默认值:结束时间

The latest date that may be selected; all later dates will be disabled.

daysOfWeekDisabled

String, Array. 默认值: '', []

Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6' or [0,6].

autoclose

Boolean. 默认值:false

当选择一个日期之后是否立即关闭此日期时间选择器。

startView

Number, String. 默认值:2, 'month'

日期时间选择器打开之后首先显示的视图。 可接受的值:

  • 0 or 'hour' for the hour view
  • 1 or 'day' for the day view
  • 2 or 'month' for month view (the default)
  • 3 or 'year' for the 12-month overview
  • 4 or 'decade' for the 10-year overview. Useful for date-of-birth datetimepickers.

minView

Number, String. 默认值:0, 'hour'

日期时间选择器所能够提供的最精确的时间选择视图。

maxView

Number, String. 默认值:4, 'decade'

日期时间选择器最高能展示的选择范围视图。

todayBtn

Boolean, "linked". 默认值: false

如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。

todayHighlight

Boolean. 默认值: false

如果为true, 高亮当前日期。

keyboardNavigation

Boolean. 默认值: true

是否允许通过方向键改变日期。

language

String. 默认值: 'en'

The two-letter code of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). Currently ships with English ('en'), German ('de'), Brazilian ('br'), and Spanish ('es') translations, but others can be added (see I18N below). If an unknown language code is given, English will be used.

forceParse

Boolean. 默认值: true

当选择器关闭的时候,是否强制解析输入框中的值。也就是说,当用户在输入框中输入了不正确的日期,选择器将会尽量解析输入的值,并将解析后的正确值按照给定的格式format设置到输入框中。

minuteStep

Number. 默认值: 5

此数值被当做步进值用于构建小时视图。对于每个 minuteStep 都会生成一组预设时间(分钟)用于选择。

pickerReferer : 不建议使用

String. 默认值: 'default' (other value available : 'input')

The referer element to place the picker for the component implementation. If you want to place the picker just under the input field, just specify input.

pickerPosition

String. 默认值: 'bottom-right' (还支持 : 'bottom-left')

此选项当前只在组件实现中提供支持。通过设置选项可以讲选择器放倒输入框下方。

viewSelect

Number or String. 默认值: same as minView (supported values are: 'decade', 'year', 'month', 'day', 'hour')

With this option you can select the view from which the date will be selected. By default it's the last one, however you can choose the first one, so at each click the date will be updated.

showMeridian

Boolean. 默认值: false

This option will enable meridian views for day and hour views.

initialDate

Date or String. 默认值: new Date()

You can initialize the viewer with a date. By default it's now, so you can specify yesterday or today at midnight ...

标记

组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>

带有重置按钮(用于清空输入框)的组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-remove"></i></span>
  4. <span class="add-on"><i class="icon-th"></i></span>
  5. </div>

方法

.datetimepicker(options)

初始化日期时间选择器。

remove

参数: None

移除日期时间选择器。同时移除已经绑定的event、内部绑定的对象和HTML元素。

  1. $('#datetimepicker').datetimepicker('remove');

show

参数: None

显示日期时间选择器。

  1. $('#datetimepicker').datetimepicker('show');

hide

参数: None

隐藏日期时间选择器。

  1. $('#datetimepicker').datetimepicker('hide');

update

参数: None

使用当前输入框中的值更新日期时间选择器。

  1. $('#datetimepicker').datetimepicker('update');

setStartDate

参数:

  • startDate (String)

给日期时间选择器设置一个新的起始日期。

  1. $('#datetimepicker').datetimepicker('setStartDate', '2012-01-01');

Omit startDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setStartDate');
  2. $('#datetimepicker').datetimepicker('setStartDate', null);

setEndDate

参数:

  • endDate (String)

给日期时间选择器设置结束日期。

  1. $('#datetimepicker').datetimepicker('setEndDate', '2012-01-01');

Omit endDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setEndDate');
  2. $('#datetimepicker').datetimepicker('setEndDate', null);

setDaysOfWeekDisabled

参数:

  • daysOfWeekDisabled (String|Array)

Sets the days of week that should be disabled.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', [0,6]);

Omit daysOfWeekDisabled (or provide an otherwise falsey value) to unset the disabled days.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled');
  2. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', null);

事件(Events)

Datetimepicker 类暴露了一组event用以对日期进行操作。

show

当选择器显示时被触发。

hide

当选择器隐藏时被触发。

changeDate

当日期被改变时被触发。

  1. $('#date-end')
  2. .datetimepicker()
  3. .on('changeDate', function(ev){
  4. if (ev.date.valueOf() < date-start-display.valueOf()){
  5. ....
  6. }
  7. });

changeYear

当十年视图上的年视图view被改变时触发。

changeMonth

当年视图上的月视图view被改变时触发。

outOfRange

当用户选择的日期超出startDate 或endDate 时,或者通过setDate 或 setUTCDate方法设置日期超出范围时被触发。

键盘支持

日期时间选择器提供了键盘导航:

up, down, left, right 方向键

这些方向键中,left/right 向后/向前 一天,up/down 向后/向前 一周。

配合shift键,up/left 向后退一个月,down/right 向前进一个月。

配置ctrl键,up/left 向后退一年,down/right 向前进一年。

Shift+ctrl 和 ctrl 同等效果 - 也就是说,他们不能同时改变月和年,只能单独改变年。

escape

escape 键可以用来隐藏、重新显示日期时间选择器;当用户希望手工编辑输入框中的值是会很有用。

enter

当选择器处于显示状态时,enter键只是将其隐藏。当选择器处于隐藏状态时,enter键发挥通常的功能 - 提交当前表单,或者其他。

I18N国际化

本插件支持月、每周中天的名称、weekStart选项的国际化。默认是语言是English ('en');其它可以使用的翻译文件在js/locales/ 目录中,只需在本插件之后引入需要的语言文件即可。需要增加额外语言支持的话,只需向 $.fn.datetimepicker.dates中增加一个key即可,一定要放在调用 .datetimepicker()之前。如下案例:

  1. $.fn.datetimepicker.dates['en'] = {
  2. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
  3. daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  4. daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
  5. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  6. monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  7. today: "Today"
  8. };

Right-to-left languages may also include rtl: true to make the calendar display appropriately.

If your browser (or those of your users) is displaying characters wrong, chances are the browser is loading the javascript file with a non-unicode encoding. Simply add charset="UTF-8" to your script tag:

  1. <script type="text/javascript" src="bootstrap-datetimepicker.de.js" charset="UTF-8"></script>

使用

绑定输入框,并设置format选项:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker">
  1. $('#datetimepicker').datetimepicker({
  2. format: 'yyyy-mm-dd hh:ii'
  3. });

绑定输入框,并设置format标记:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker" data-date-format="yyyy-mm-dd hh:ii">
  1. $('#datetimepicker').datetimepicker();

作为组件使用:

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input size="16" type="text" value="12-02-2012" readonly>
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>
  1. $('#datetimepicker').datetimepicker();

作为内联日期时间选择器:

  1. <div id="datetimepicker"></div>
    1. $('#datetimepicker').datetimepicker();

关于bootstrap-datetimepicker 插件的配置参数详解的更多相关文章

  1. mha配置参数详解

    mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...

  2. reids配置参数详解

    转自:http://www.jb51.net/article/60627.htm reids配置参数详解 #daemonize no  默认情况下, redis 不是在后台运行的,如果需要在后台运行, ...

  3. nginx配置参数详解

    配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍 ...

  4. Redis配置参数详解

    Redis配置参数详解 /********************************* GENERAL *********************************/ // 是否作为守护进 ...

  5. MHA配置参数详解 【转】

    mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...

  6. zookeeper的配置参数详解(zoo.cfg)

    配置参数详解(主要是%ZOOKEEPER_HOME%/conf/zoo.cfg文件) 参数名 说明 clientPort 客户端连接server的端口,即对外服务端口,一般设置为2181吧. data ...

  7. HAproxy 配置参数详解

    HAproxy 配置参数详解 /etc/haproxy/haproxy.cfg # 配置文件 ----------------------------------------------------- ...

  8. samba 配置参数详解

    samba 配置参数详解: 一.全局配置参数  workgroup = WORKGROUP说明:设定 Samba Server 所要加入的工作组或者域. server string = Samba S ...

  9. [转帖]持久化journalctl日志清空命令查看配置参数详解

    持久化journalctl日志清空命令查看配置参数详解 最近 linux上面部署服务 习惯使用systemd 进行处理 这样最大的好处能够 使用journalctl 进行查看日志信息. 今天清理了下 ...

随机推荐

  1. com.android.ddmlib.SyncException: Read-only file system

    通过eclipse运行Android 程序到测试机时候 控制台出现如下错误: [2014-02-13 15:06:03 - MPlay] Failed to install MPlay.apk on ...

  2. 一个 developer 的进化

    作为一名开发者已十年,回顾过往大概经历了这么几个阶段,如下图所示: Develop Code 作为刚走出学校的学生进入公司,在最初的 1-2 年内就处于该阶段. 不停的开发代码,为系统的大厦添砖加瓦, ...

  3. java面试之常见编程题

    1.编程实现:二分搜索算法 解答: public class SearchTest { /** 被搜索数据的大小 */ private static final int size = 5000000; ...

  4. Learning ROS for Robotics Programming Second Edition学习笔记(七) indigo PCL xtion pro live

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS forRobotics Pro ...

  5. "《算法导论》之‘排序’":线性时间排序

    本文参考自一博文与<算法导论>. <算法导论>之前介绍了合并排序.堆排序和快速排序的特点及运行时间.合并排序和堆排序在最坏情况下达到O(nlgn),而快速排序最坏情况下达到O( ...

  6. android bitmap压缩几种色彩详解

    android中的大图片一般都要经过压缩才显示,不然容易发生oom,一般我们压缩的时候都只关注其尺寸方面的大小,其实除了尺寸之外,影响一个图片占用空间的还有其色彩细节. 打开Android.graph ...

  7. 【LaTeX排版】LaTeX论文模版

    本文是对前面LaTeX论文排版文章的总结.前面的几篇文章是分别从论文的几个方面来讲述LaTeX的排版问题,这里综合了前面的内容,给出了论文排版的模版. 模版的使用: 1.首先建立一个main.tex文 ...

  8. Activity之间传递大数据问题

    Android开发人员都知道,Intent适用于在不同的Activity之间传递数据,包括参数.字符串.以及序列化的对象等.但是笔者所做的项目用到了使用Intent 传递Bitmap图片对象,图片的数 ...

  9. 初探linux子系统集之i2c子系统(一)

    I2c子系统在进公司来的时候就学习过了,可是那是还不是很熟悉linux中的i2c子系统,就没有细看.记得当初很想熟悉linux中的各种总线驱动,想专门写一个关于总线驱动的专集,后来发现好像就没有几个, ...

  10. 使用XStream是实现XML与Java对象的转换(1)--简介及入门示例

    一.简单介绍 XStream是thoughtworks开发的开源框架,用于实现XML数据于Java对象.Json数据的转换.它不需要schema或其他的mapping文件就可以进行java对象和xml ...