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
1374 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)

<!--选择时间 datetimepicker 选择到天-->
<p>
 <label class="date-label-width">时间(To Date):</label>
 <p class="input-group date form_datetime date-p-inline">
  <input type="datetime" size="16" id="startTime" name="startTime" class="date-input-size date-minute-bgcolor" value="" readonly >
  <span class="input-group-addon date-p-inline"><span class="fa fa-calendar fa-lg"></span></span>
 </p>

 <label for="endTime" >-</label>
 <p class="input-group date form_datetime date-p-inline">
  <input type="datetime" id="endTime" name="endTime" class="date-input-size date-minute-bgcolor" value="" readonly>
  <span class="input-group-addon date-p-inline"><span class="fa fa-calendar fa-lg"></span></span>
 </p>
</p>
Copy after login

JS code

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

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

<!--选择时间 datetimepicker 选择到分钟-->
<p>
 <label for="dtp_input1" class="date-label-width">时间(To Minute):</label>
 <p class="input-group date form_datetime date-p-inline" data-date="" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
  <input class="date-input-size " id="startTimeMinute" size="16" type="text" value="" readonly>
  <span class="input-group-addon date-p-inline"><span class="fa fa-calendar fa-lg"></span></span>
  <!--<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>-->
 </p>
 <input type="hidden" id="dtp_input1" value="" />

 <label for="dtp_input2">-</label>
 <p class="input-group date form_datetime date-p-inline" data-date="" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
  <input class="date-input-size " id="endTimeMinute" size="16" type="text" value="" readonly>
  <span class="input-group-addon date-p-inline"><span class="fa fa-calendar fa-lg"></span></span>
  <!--<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>-->
 </p>
 <input type="hidden" id="dtp_input2" value="" />
</p>
Copy after login

(JS Code)

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

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

}).on("changeDate", function () {
 $(&#39;#startTimeMinute&#39;).datetimepicker(&#39;setEndDate&#39;, $("#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