JSFiddle - React, Tailwind, and code Playground

by adeneo

HTML

Type time here : <input id="first" /><br/><br />
+ 2 hours here : <input id="second" />

JavaScript

var first  = document.getElementById('first');
var second = document.getElementById('second');

first.addEventListener('input', function() {

    if (this.value.indexOf(':') != -1 && this.value.length === 5) {
    
        var date  = new Date();
        var val   = this.value.split(':');
        date.setHours( parseInt(val[0], 10) + 2);
        
        var hours = date.getHours();
        hours = hours > 9 ? hours : '0' + hours;
        
        second.value = hours + ':' + val[1];
    }

}, false);