खुद का Age Calculator
Application
बनाएं – HTML Code के साथ
यह पोस्ट क्यों खास है?
यह Code आपके लिए क्या करेगा?
Code को Blogger Post में कैसे Paste करें?
full code copy 👇👇
<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>उम्र कैलकुलेटर</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #e0f7fa, #ffffff);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.app-wrapper {
background: #ffffff;
padding: 25px 20px;
border-radius: 16px;
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
}
.app-wrapper h2 {
text-align: center;
margin-bottom: 20px;
color: #00796b;
font-size: 22px;
}
label {
display: block;
font-weight: bold;
margin-bottom: 8px;
color: #333;
font-size: 16px;
}
input[type="date"] {
width: 100%;
padding: 12px;
border: 2px solid #00acc1;
border-radius: 10px;
font-size: 16px;
outline: none;
margin-bottom: 20px;
}
.btn {
width: 100%;
padding: 12px;
background: #00acc1;
color: white;
border: none;
border-radius: 10px;
font-size: 16px;
cursor: pointer;
transition: background 0.3s ease;
}
.btn:hover {
background: #00838f;
}
.result-box {
margin-top: 20px;
background: #e0f2f1;
padding: 15px;
border-radius: 10px;
font-size: 15px;
color: #004d40;
font-weight: 500;
line-height: 1.6;
display: none;
}
@media (max-width: 480px) {
.app-wrapper {
margin: 20px;
padding: 20px 15px;
}
.app-wrapper h2 {
font-size: 20px;
}
input[type="date"],
.btn {
font-size: 15px;
}
.result-box {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="app-wrapper">
<h2>अपनी उम्र जानें</h2>
<label for="dob">जन्मतिथि चुनें:</label>
<input type="date" id="dob" max="" />
<button class="btn" onclick="calculateAge()">गणना करें</button>
<div class="result-box" id="resultSection"></div>
</div>
<script>
document.getElementById('dob').max = new Date().toISOString().split('T')[0];
function calculateAge() {
const dobInput = document.getElementById('dob').value;
if (!dobInput) {
alert('कृपया अपनी जन्मतिथि चुनें।');
return;
}
const dob = new Date(dobInput);
const now = new Date();
if (dob > now) {
alert('भविष्य की जन्मतिथि मान्य नहीं है।');
return;
}
let diffMs = now - dob;
const years = Math.floor(diffMs / (1000 * 60 * 60 * 24 * 365.25));
diffMs -= years * (1000 * 60 * 60 * 24 * 365.25);
const months = Math.floor(diffMs / (1000 * 60 * 60 * 24 * 30.44));
diffMs -= months * (1000 * 60 * 60 * 24 * 30.44);
const weeks = Math.floor(diffMs / (1000 * 60 * 60 * 24 * 7));
diffMs -= weeks * (1000 * 60 * 60 * 24 * 7);
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
diffMs -= days * (1000 * 60 * 60 * 24);
const hours = Math.floor(diffMs / (1000 * 60 * 60));
diffMs -= hours * (1000 * 60 * 60);
const minutes = Math.floor(diffMs / (1000 * 60));
diffMs -= minutes * (1000 * 60);
const seconds = Math.floor(diffMs / 1000);
const result =
'आपकी उम्र है: ' + years + ' वर्ष, ' + months + ' महीने, ' + weeks + ' हफ्ते, ' +
days + ' दिन, ' + hours + ' घंटे, ' + minutes + ' मिनट, और ' + seconds + ' सेकंड।';
const resultBox = document.getElementById('resultSection');
resultBox.innerHTML = result;
resultBox.style.display = 'block';
}
</script>
</body>
</html>
0 टिप्पणियाँ