Home > Web Front-end > JS Tutorial > body text

Example of usage of bootstrap-datetimepicker time plug-in in angular project

亚连
Release: 2018-05-30 10:13:06
Original
1217 people have browsed it

This article mainly introduces the usage examples of bootstrap-datetimepicker time plug-in in angular project. Now I will share it with you and give you a reference.

1. Requirements:

A function often used in the background system, select a time interval and filter some information based on this time interval, for example, a certain Registered users during the time period.

2. Final effect

##3. Files that need to be imported (src/index.html)

Note: 1. The jQuery file is referenced first, because on the initialization date of the plug-in, you need to find the object in the DOM and add some styles;

2. As you can see, the bootstrap.min.css file is not referenced in my project, because this style is globally referenced in index.html, which has a great impact on the already written styles, so the impact is that the styles are messy. Otherwise, the style of the rendering you see (the first picture) needs to be done by yourself. Write a common style and reference it in each component.

I won’t add the specific styles. I believe that if you come across this pitfall of citing the plug-in, just think of a creamy chocolate and slowly 'taste' it with a sense of accomplishment~

4. Code part

A. To Date

(html code)


Copy after login

JS code

//初始化日期插件 -- 选择到天
$('#startTime').datetimepicker({
 format: 'yyyy-mm-dd',//显示格式
 todayHighlight: 1,//今天高亮
 minView: "month",//设置只显示到月份
 startView:2,
 forceParse: 0,
 showMeridian: 1,
 autoclose: true,//选择后自动关闭
 language: 'zh-CN',
 weekStart: 1,
 // todayBtn: 1,
 // autoclose: 1,
 // todayHighlight: 1,
 // startView: 2,
 // minView: 2,
 // forceParse: 0,
 // pickerPosition:'bottom-right'//日期插件弹出的位置
}).on("changeDate", function () {
 $('#endTime').datetimepicker('setStartDate', $("#startTime").val());
 console.log( $("#startTime").val());
 $("#endTime").focus()
});

$('#endTime').datetimepicker({
 format: 'yyyy-mm-dd',//显示格式
 todayHighlight: 1,//今天高亮
 minView: "month",//设置只显示到月份
 startView:2,
 forceParse: 0,
 showMeridian: 1,
 autoclose: true,//选择后自动关闭
 language: 'zh-CN',
 weekStart: 1,
 // todayBtn: 1,
 // autoclose: 1,
 // todayHighlight: 1,
 // startView: 2,
 // minView: 2,
 // forceParse: 0,
 // pickerPosition:'bottom-right'//日期插件弹出的位置
}).on("changeDate", function () {
 $('#startTime').datetimepicker('setEndDate', $("#endTime").val());
 console.log( $("#endTime").val());
});
Copy after login

format This parameter can set the date format, yyyy-mm-dd, yyyy/mm/dd

B, To Minute

(html code)


Copy after login

(JS Code)

// //初始化日期插件 -- 选择到分钟
$('#startTimeMinute').datetimepicker({
 //language: 'fr',
 format: 'yyyy-mm-dd hh:ii',//显示格式
 weekStart: 1,
 todayBtn: 1,
 autoclose: 1,
 todayHighlight: 1,
 startView: 2,
 forceParse: 0,
 showMeridian: 1
}).on("changeDate", function () {
 $('#endTimeMinute').datetimepicker('setStartDate', $("#startTimeMinute").val());
 console.log( $("#startTimeMinute").val());
 $("#endTimeMinute").focus()
});

$('#endTimeMinute').datetimepicker({
 //language: 'fr',
 format: 'yyyy-mm-dd hh:ii',//显示格式
 weekStart: 1,
 todayBtn: 1,
 autoclose: 1,
 todayHighlight: 1,
 startView: 2,
 forceParse: 0,
 showMeridian: 1

}).on("changeDate", function () {
 $('#startTimeMinute').datetimepicker('setEndDate', $("#endTimeMinute").val());
 console.log( $("#endTimeMinute").val());
});
Copy after login

Note: Because it is a time interval, the first input is the start time, the second is the end time, the start time must be before the end time, therefore, the id must be added to the input, and Not p.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solve the problem of permissions when installing as npm administrator

The concept of JS anonymous functions and anonymous self-executing functions Example of mouse interaction with usage analysis

p5.js introductory tutorial

The above is the detailed content of Example of usage of bootstrap-datetimepicker time plug-in in angular project. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!