सबसे पहले, करंट डेट प्राप्त करें:
var currentDateTime = new Date();
करंट डेट/टाइम को सेकंड में प्राप्त करने के लिए, getTime()/1000 का उपयोग करें।
उदाहरण
निम्नलिखित कोड है:
var currentDateTime = new Date();
console.log("The current date time is as follows:");
console.log(currentDateTime);
var resultInSeconds=currentDateTime.getTime() / 1000;
console.log("The current date time in seconds is as follows:")
console.log(resultInSeconds);
उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js
यहां, मेरा फ़ाइल नाम demo285.js है।
आउटपुट
यह कंसोल पर निम्नलिखित आउटपुट देगा:
The current date time is as follows: 2020-08-28T16:13:35.987Z The current date time in seconds is as follows: 1598631215.987