根据您的最新评论,我相信您希望用户能够选择日期(日/月/年),但时间(小时/分钟)会随着时间推移而变化,直到当前时间+ 3小时.如果是这样,您可以使用类似以下内容的方法:$(function () { $('#datetimepicker').datetimepicker({ minDate: moment().startOf('minute').add(180, 'm'), });});setInterval(function(){ var pickedDate = $('#datetimepicker').data('DateTimePicker').date(); var currentDate = moment(); pickedDate = pickedDate.set({ 'hour' : currentDate.get('hour') + 3, 'minute' : currentDate.get('minute'), 'second' : currentDate.get('second') }); $('#datetimepicker').data("DateTimePicker").date(pickedDate); },1000);您可以在此处进行测试: https://jsfiddle.net/8jpmkcr5/98/ My HTML code like this:$(function () { $('#datetimepicker').datetimepicker({ minDate: moment().startOf('minute').add(300, 'm'), }); $("#btnSubmit").click(function() { value = document.getElementById('datetimepicker').value; console.log(value) });});<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/><link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/><div class="container"> <div class="row"> <div class='col-sm-6'> <div class="form-group"> <input type='text' class="form-control" id='datetimepicker' /> </div> </div> </div></div><button id="btnSubmit"> Submit</button>Demo like this : https://jsfiddle.net/oscar11/8jpmkcr5/83/If I click submit button, I successfully get the datetime value 300 minutes from nowBut if before submitting, I wait 10 minutes, the result does not match my expectationsFor example now at 6 o'clock. Before submit I wait 10 minutes. After submit, the time value I get is 11.10. So I want to like itHow can I do that?How do I make the automatic datetime value increase?Update :Whether the time value in textfield can be automatically increased based on current time? 解决方案 Not sure why would you need it, but you can use something like:$("#btnSubmit").click(function() { var targetDate = new Date(new Date().getTime() + (300 * 60 * 1000)); $('#datetimepicker').data("DateTimePicker").date(targetDate); value = document.getElementById('datetimepicker').value; console.log(targetDate, value);});On click, it will change the datetimepicker to the current date + 300 minutes.I've updated the example: https://jsfiddle.net/8jpmkcr5/86/EDIT:Based on your latest comment, i believe you want the use to be able to pick the date (day/month/year) but the time (hour/minutes) keep changing as time passes to current time + 3 hours. If thats the case you can use something like:$(function () { $('#datetimepicker').datetimepicker({ minDate: moment().startOf('minute').add(180, 'm'), });});setInterval(function(){ var pickedDate = $('#datetimepicker').data('DateTimePicker').date(); var currentDate = moment(); pickedDate = pickedDate.set({ 'hour' : currentDate.get('hour') + 3, 'minute' : currentDate.get('minute'), 'second' : currentDate.get('second') }); $('#datetimepicker').data("DateTimePicker").date(pickedDate); },1000);You can test here: https://jsfiddle.net/8jpmkcr5/98/ 这篇关于如何创建动态的datetimepicker值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!