Date ऑब्जेक्ट जावास्क्रिप्ट भाषा में बिल्ट-इन एक डेटा टाइप है। Date ऑब्जेक्ट्स को new Date() के साथ बनाया जाता है जैसा कि नीचे दिखाया गया है।
एक बार Date ऑब्जेक्ट बन जाने के बाद, कई मेथड्स आपको इस पर ऑपरेट करने की अनुमति देते हैं। अधिकांश मेथड्स आपको ऑब्जेक्ट के वर्ष, महीना, दिन, घंटा, मिनट, सेकंड और मिलीसेकंड फील्ड्स को प्राप्त करने और सेट करने की अनुमति देते हैं, चाहे लोकल टाइम हो या UTC (यूनिवर्सल, या GMT) टाइम।
toLocaleString() फ़ंक्शन डेट ऑब्जेक्ट का वर्तमान डेट (समय सहित) लौटाता है।
सिंटैक्स
इसका सिंटैक्स निम्नानुसार है
dateObj.toLocaleString([locales[, options]])
उदाहरण
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> const dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Date: "+dateObj.toLocaleString()); </script> </body> </html>आउटपुट
Current Date: 9/26/1989, 12:04:25 PM
उदाहरण
यदि आप डेट ऑब्जेक्ट के कंस्ट्रक्टर को कुछ भी पास नहीं करते हैं तो यह फ़ंक्शन सिस्टम की वर्तमान डेट लेता है और उसका स्ट्रिंग फॉर्मेट लौटाता है।
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> const dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Date: "+dateObj.toLocaleString()); </script> </body> </html>आउटपुट
Current Date: 26/09/1989, 12:04:25 PM
उदाहरण
आप इस फ़ंक्शन को स्ट्रिंग पैरामीटर के रूप में पास करके आवश्यक स्ट्रिंग फॉर्मेट भी निर्दिष्ट कर सकते हैं।
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> const dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Date: "+dateObj.toLocaleString("en-us")); </script> </body> </html>आउटपुट
Current Date: 9/26/1989, 12:04:25 PM