One solution is to convert the string value of the initial datetime textboxes to a Date
object of Javascript only and add a time to the value of it. After that, just convert it back to two strings and put the value in the final date and time textboxes. I made a snippet, take a look.
function calculaDataHoraFinal() {
var valorDataIni = $("#data-ini").val();
var valorHoraIni = $("#hora-ini").val();
if (valorDataIni && valorHoraIni) {
var partesData = valorDataIni.split("/");
var partesHora = valorHoraIni.split(":");
var dataIni = new Date(partesData[2], partesData[1] - 1, partesData[0], partesHora[0], partesHora[1]);
var dataFim = new Date(dataIni.getTime());
dataFim.setHours(dataFim.getHours() + 1);
var partesHoraFim = dataFim.toTimeString().split(':');
$("#data-fim").val(dataFim.toLocaleDateString());
$("#hora-fim").val(partesHoraFim[0] + ':' + partesHoraFim[1]);
}
}
$("#data-ini, #hora-ini").on('change', calculaDataHoraFinal);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><inputid="data-ini" type="text" />
<input id="hora-ini" type="text" /> até
<input id="data-fim" type="text" />
<input id="hora-fim" type="text" />
</div>
I know there are date and format parsing methods, but they all depend on the location of the browser, and the culture definition for those methods is not well implemented in all browsers. If you want to make things simpler, you can use a date processing library for Javascript like Moment.js .