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?
This question is related to
node.js
NodeJS (and newer browsers) have a nice shortcut to get the current time in milliseconds.
var timeInMss = Date.now()
Which has a performance boost compared with
var timeInMss = new Date().getTime()
Because you do not need to create a new object.
var datetime = new Date();_x000D_
console.log(datetime.toISOString().slice(0,10));
_x000D_
GMT -03:00 Example
new Date(new Date()-3600*1000*3).toISOString();
To create a new Date object in node.js
, or JavaScript
in general, just call it’s initializer
var d = new Date();
var d = new Date(dateString);
var d = new Date(jsonDate);
var d = new Date(year, month, day);
var d = new Date(year, month, day, hour, minute, second, millisecond);
Remember that Date objects can only be instantiated by calling Date
or using it as a constructor; unlike other JavaScript object types, Date objects have no literal syntax
Node.js is a server side JS platform build on V8 which is chrome java-script runtime.
It leverages the use of java-script on servers too.
You can use JS Date() function or Date class.
Source: Stackoverflow.com