Htmlviewer HTML
Htmlviewer HTML
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Spent and Money Earned Timer</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f3f3f3;
}
.timer {
font-size: 1.5em;
margin: 10px 0;
}
#money {
color: red;
/* Money earned in red */
}
button {
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
margin-top: 10px;
}
</style>
</head>
<body>
<h1>Time Spent and Money Earned</h1>
<div class="timer">Time Spent: <span id="time">00:00:00</span>
</div>
<div class="timer">Money Earned: ₹ <span id="money">0.00</span>
</div>
<button onclick="startTimer()">Start</button>
<button onclick="stopTimer()">Stop</button>
<button onclick="resetTimer()">Reset</button>
<script>
let startTime = null;
let interval;
const ratePerSecond = 0.035; // Earning rate in rupees per second
function formatTime(seconds) {
const hrs = String(Math.floor(seconds / 3600)).padStart(2, '0');
const mins = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0');
const secs = String(seconds % 60).padStart(2, '0');
return `${hrs}:${mins}:${secs}`;
}
function updateTimeAndMoney() {
if (startTime) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000); // Time
in seconds
const earnedMoney = (elapsedTime * ratePerSecond).toFixed(2); // Money
earned in rupees
document.getElementById("time").textContent = formatTime(elapsedTime);
document.getElementById("money").textContent = earnedMoney;
}
}
function startTimer() {
if (!interval) {
if (!startTime) {
startTime = Date.now();
}
interval = setInterval(updateTimeAndMoney, 1000); // Update every second
}
}
function stopTimer() {
clearInterval(interval);
interval = null;
}
function resetTimer() {
stopTimer();
startTime = null;
document.getElementById("time").textContent = "00:00:00";
document.getElementById("money").textContent = "0.00";
}
</script>
</body>
</html>