Display Default Tomorrow Date And Time As 8Am In Date Field
Hi all i am trying to display tomorrow date and time(8am) in my date field. as i have tried some code it is showing only tomorrow date but not time can any one help me how to s
Solution 1:
First you need to change your input type to datetime-local. So that it will support for date & time. Then use the moment to format date.
$("#inputDate").val(moment().add(1, 'days').hours(8).startOf('hour').format("YYYY-MM-DDTHH:mm:ss"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<div class="col-xs-6 date" style="display:block;">
<input class="form-control" type="datetime-local" id="inputDate" value="" />
</div>
Solution 2:
You can use moment.JS for formatting and operation on the date.
http://momentjs.com/downloads/moment.js
var tomorrow = moment(new Date())
.add(1,'days')
.hours(8)
.minutes(30)
.format('DD/MMM/YYYY HH:mm');
console.log(tomorrow)
Solution 3:
var a = new Date;
a.setDate(a.getDate()+1);
a.setHours(8);
a.setMinutes(0);
a.setSeconds(0);
console.log(a);
Post a Comment for "Display Default Tomorrow Date And Time As 8Am In Date Field"