📅  最后修改于: 2023-12-03 14:40:38.461000             🧑  作者: Mango
Datetimepicker is a popular jQuery plugin that adds a datetime picker widget to your form or webpage. It provides a user-friendly way for users to select a date and time or a range of dates.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<div class="form-group">
<label for="datetimepicker">Select date and time:</label>
<div class="input-group date" id="datetimepicker">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
$(document).ready(function() {
$('#datetimepicker').datetimepicker();
});
format
: Defines the date and time format. Default is 'YYYY-MM-DD HH:mm:ss'
.minDate
: Defines the minimum date that can be selected.maxDate
: Defines the maximum date that can be selected.defaultDate
: Defines the default date and time that will be displayed.showTodayButton
: Enables or disables the "Today" button that sets the date to the current date.showClear
: Enables or disables the "Clear" button that clears the input field.useCurrent
: Defines whether to display the current date and time when the datetimepicker is initialized. Default is true
.date
: Gets or sets the selected date and time. If called with a parameter, sets the selected date and time. If called without a parameter, gets the selected date and time.minDate
: Gets or sets the minimum date that can be selected. If called with a parameter, sets the minimum date. If called without a parameter, gets the minimum date.maxDate
: Gets or sets the maximum date that can be selected. If called with a parameter, sets the maximum date. If called without a parameter, gets the maximum date.disable
: Disables the datetimepicker.enable
: Enables the datetimepicker.Datetimepicker is a powerful jQuery plugin that makes it easy to add a datetime picker widget to your form or webpage. It provides a simple and intuitive interface that allows users to select a date and time or a range of dates. With its many options and methods, it can be customized to suit your needs.