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?
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.
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.
now() The static Date. now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
You do that as you would in a browser:
var datetime = new Date(); console.log(datetime);
var datetime = new Date(); console.log(datetime.toISOString().slice(0,10));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With