Date.prototype.constructor प्रॉपर्टी उस कंस्ट्रक्टर फंक्शन को संदर्भित करती है जिसने Date इंस्टेंस का प्रोटोटाइप बनाया। यह सभी Date ऑब्जेक्ट्स पर Date फंक्शन की ओर इशारा करती है।
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style>
body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding: 20px; }
.sample { font-size: 20px; font-weight: 500; }
button { padding: 10px 20px; background: #17a2b8; color: white; border: none; border-radius: 4px; cursor: pointer; }
</style> </head> <body>
<h1>Date Constructor प्रॉपर्टी</h1>
<div class="sample"></div>
<button class="Btn">Date Constructor देखें</button>
<h3>ऊपर दिए गए बटन पर क्लिक करके Date Constructor फंक्शन देखें</h3>
<script>
const fillEle = document.querySelector(".sample");
const date = new Date();
fillEle.innerHTML = "वर्तमान दिनांक: " + date + "<br>";
document.querySelector(".Btn").addEventListener("click", () => {
fillEle.innerHTML += "Constructor: " + date.constructor;
});
</script> </body> </html>
आउटपुट
वर्तमान दिनांक: [वर्तमान तारीख/समय]Constructor: function Date() { [native code] }
Date Constructor के उपयोग
// 1. नई तारीख बनाना
new Date(); // अभी
new Date(milliseconds); // यूनिक्स एपोक से मिलीसेकंड
new Date(dateString); // पार्स करने योग्य स्ट्रिंग
new Date(year, month, day, hours, minutes, seconds, ms);
// महीना 0-आधारित है (0 = जनवरी)
new Date(2024, 0, 1); // 1 जनवरी 2024
// 2. constructor प्रॉपर्टी का उपयोग
const d = new Date();
d.constructor === Date; // true
// 3. टाइप चेकिंग के लिए
function isDate(obj) {
return obj instanceof Date && obj.constructor === Date;
}
महत्वपूर्ण Date मेथड्स
| मेथड | विवरण |
|---|---|
getFullYear() | 4-अंकीय वर्ष |
getMonth() | महीना (0-11) |
getDate() | महीने का दिन (1-31) |
getDay() | सप्ताह का दिन (0-6, 0=रविवार) |
getHours() | घंटे (0-23) |
getMinutes() | मिनट (0-59) |
getSeconds() | सेकंड (0-59) |
getTime() | 1970 से मिलीसेकंड |
Date.now() | स्थैतिक: वर्तमान टाइमस्टैप |