Reputation: 1937
I have this html:
<input required="" id="time" type="time">
js:
var time = $('#time').val();
console.log(time); // it outputs e.g. 10:00
var newTime = time--; // NaN
var convert = new Date(time); // Invalid Date
How to work with the value of input? I want to compare it to the other input's value or other basic operations like decrease time with 1 hour but I'm not able to convert it to Date object.
Upvotes: 1
Views: 9825
Reputation: 1
Try using valueAsDate
property
$("input[type=time]").on("change", function() {
console.log(this.valueAsDate)
})
<input required="" id="time" type="time">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Upvotes: 2