Calculate 1 hour form a date , application of this code where we want to set one hour from start date for calculation of end date .
for example :
we have a case where we want to set start date for an event so the start date is = 11:10 am then this code calculate one end date which will be 12:10 pm
you can use dateTimeC or dateTimeC2 both has same result .
function dateTimeC(date) {var hours = date.getHours();var hours = (hours + 24) % 24;var mid = 'AM';if (hours == 0) {hours = 12;}else if (hours >= 12) {hours = hours % 12;mid = 'PM';}console.log(hours + ':00' + mid);if (hours == 12 && mid == 'PM') {console.log('end time 01:00 AM');}else {console.log('end time', (hours + 1 + ':00 ' + mid));}}console.log('%c Case 1', 'color:red');var date = new Date('06/01/2020 11:00:00');dateTimeC2(date)console.log('%c Case 2', 'color:red');var date = new Date('06/01/2020 00:20:00');dateTimeC2(date)console.log('%c Case 3', 'color:red');var date = new Date('06/01/2020 23:20:00');dateTimeC2(date)function dateTimeC2(date) {var dt = date;dt.setMinutes(00, 00, 00);console.log('start time ', dt.toLocaleTimeString());dt.setTime(dt.getTime() + (1 * 60 * 60 * 1000))console.log('end time ', dt.toLocaleTimeString())}
Comments
Post a Comment