Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get date in application run by node.js?

Tags:

node.js

Do I have to manually run date command using child_process and fetch the result from it to get the date? Is there any other way using node?

like image 773
user482594 Avatar asked Dec 19 '11 09:12

user482594


People also ask

How do I get current date in node JS?

Since Node. js is based on JavaScript, you can use the Date object methods getDate() , getMonth() , and getFullYear() to get the current day, month, and year in a Node.

How do I pass a date in node JS?

Either use ISO 8601 format as Phil suggested, or simply pass the date as milliseconds (since 1970). For example, new Date(1447378736842) is the same as new Date("2015-11-13T01:38:56.842Z") . To get the current date in ISO 8601 format, you might do something like this: var d = new Date(); var n = d.

What does date now () produce?

now() The static Date. now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.


Video Answer


2 Answers

You do that as you would in a browser:

    var datetime = new Date();      console.log(datetime);
like image 55
alessioalex Avatar answered Sep 21 '22 03:09

alessioalex


    var datetime = new Date();      console.log(datetime.toISOString().slice(0,10));
like image 22
Aikansh Mann Avatar answered Sep 23 '22 03:09

Aikansh Mann