In the val docs written this description:
.val() Returns: String, Number, Array
I tried to get a Time, but it seems to return string only, Is there any method to parse the val value to localtime?
$.get(href,function(exam,status){
$('#startTimeEdit').val(exam.startTime);
$('#endTimeEdit').val(exam.endTime);
});
Overall, my question will be how to parse the val value to LocalTime datatype?
CodePudding user response:
If you're given a stringified date time in these values, then this will work:
$.get(href, (exam, status) => {
const start = new Date($('#startTimeEdit').val(exam.startTime)).toLocaleTimeString()
const end = new Date($('#endTimeEdit').val(exam.endTime)).toLocaleTimeString()
return { start, end }
});