📌  相关文章
📜  datetimepicker (1)

📅  最后修改于: 2023-12-03 14:40:38.461000             🧑  作者: Mango

Datetimepicker Theme

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.

Features
  • Allows users to easily select a date and time or a range of dates
  • Customizable through various options and methods
  • Supports multiple languages and date formats
  • Smooth animation effects
  • Compatible with different browsers and devices
How to use
  1. Include the necessary files:
<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>
  1. Add a datetimepicker widget to your form element:
<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>
  1. Initialize the datetimepicker:
$(document).ready(function() {
  $('#datetimepicker').datetimepicker();
});
Options
  • 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.
Methods
  • 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.
Conclusion

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.