daterangepicker的使用手册

daterangepicker可以选择时间范围也可以根据实际业务需要单选日期,可精确到秒。

使用方法:

1.在项目中引入插件文件daterangepicker.css、moment.min.js、daterangepicker.js(注意顺序)

实现如图效果:(单选+中文)

js初始化:

$('#searchDate').daterangepicker({
		   "autoApply": true, //选择日期后自动提交;只有在不显示时间的时候起作用timePicker:false
	        singleDatePicker: true, //单日历
	        showDropdowns: true, //年月份下拉框  
	        //startDate: moment().hours(0).minutes(0).seconds(0), //设置开始日期 
	        "opens": "center",
	        showWeekNumbers: true,
	        locale: {
	            format: "YYYY-MM-DD", //设置显示格式
	            applyLabel: '确定', //确定按钮文本
	            cancelLabel: '取消', //取消按钮文本
	            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
	            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
	                '七月', '八月', '九月', '十月', '十一月', '十二月'
	            ],
	            firstDay: 1
	        },
	    }, function(start) {
	        console.log(start.format('YYYY-MM-DD HH:mm:ss'));
	    });

实现如图效果:(选择时间范围+中文)

js初始化:

$('#holiday_date').daterangepicker({ 
		  timePicker: true, //显示时间
		           timePicker24Hour: true, //时间制
		           timePickerSeconds: true, //时间显示到秒
		          startDate: moment().hours(0).minutes(0).seconds(0), //设置开始日期
		         endDate: moment(new Date()), //设置结束器日期
		          // maxDate: moment(new Date()), //设置最大日期
		           "opens": "center",
		           ranges: {
		             // '今天': [moment(), moment()],
             '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
		             '上周': [moment().subtract(6, 'days'), moment()],
		             '前30天': [moment().subtract(29, 'days'), moment()],
		              '本月': [moment().startOf('month'), moment().endOf('month')],
		              '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
		         },
		         showWeekNumbers: true,
		         locale: {
		             format: "YYYY-MM-DD HH:mm:ss", //设置显示格式
		             applyLabel: '确定', //确定按钮文本
		             cancelLabel: '取消', //取消按钮文本
		             customRangeLabel: '自定义',
		             daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
		              monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
		                 '七月', '八月', '九月', '十月', '十一月', '十二月'
		              ],
		              firstDay: 1
		         },
		     }, function(start, end, label) {
		         timeRangeChange = [start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss')];
		         console.log(timeRangeChange);
		     });

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值