Write a JavaScript program to read a time from user and perform the following, if entered value is time then perform the following
1.Display the hour from the time
2.Display the minute from the time
3.Display the second from the time
4.Change the hour to next hour
5.Change the minute to next minute
6.change the second to next second
<html>
<head>
<title>Time Processor</title>
<script>
function processTime()
{
var timeInput = document.getElementById("timeInput").value;
var timeParts = timeInput.split(":");
if (timeParts.length !== 3)
{
alert("Invalid time format.Please enter time in HH:MM:SS format.");
return;
}
var hour = parseInt(timeParts[0]);
var minute = parseInt(timeParts[1]);
var second = parseInt(timeParts[2]);
document.getElementById("hr").value = hour;
document.getElementById("min").value = minute;
document.getElementById("sec").value = second;
var nexthr=(hour + 1)%24; document.getElementById("nexthr").value=nexthr;
var nextmin=(minute + 1)%60;
document.getElementById("nextmin").value=nextmin;
var nextsec=(second + 1)%60;
document.getElementById("nextsec").value=nextsec;
}
</script>
</head>
<body>
<h1>Time Processor</h1>
<h3> Enter Time (HH:MM:SS): <input type="text" id="timeInput" value="00:00:00">
<button onclick="processTime()">Process Time</button> </h3>
<table border="1">
<tr>
<td> Hour: </td>
<td> <input type="text" id="hr" readonly> </td>
</tr>
<tr>
<td> Minute </td>
<td> <input type="text" id="min" readonly> </td>
</tr>
<tr>
<td> Second: </td>
<td> <input type="text" id="sec" readonly> </td>
</tr>
<tr>
<td> Next Hour: </td>
<td> <input type="text" id="nexthr" readonly> </td>
</tr>
<tr>
<td> Next Minute:</td>
<td> <input type="text" id="nextmin" readonly> </td>
</tr>
</tr>
<td> Next Second:</td>
<td> <input type="text" id="nextsec" readonly> </td>
</tr>
</table>
</body>
</html>
No comments:
Post a Comment