I currently have a date picker on the client side. Once a date is selected the date in milliseconds is sent to my node app. the problem is i am getting Invalid Date for new Date(milliseconds)
the milliseconds sent look like this ( 1347433200000 ) my code is as fallows
app.get('/dashboard/date/:date', function(req, res){
console.log(new Date(req.params.date));
var start = new Date(req.params.date);
var end = new Date(req.params.date).add({hours:23, minutes:59, seconds: 59, milliseconds: 999});
console.log(start);
console.log(end);
Appointments.find({'scheduled' : {"$gte": start, "$lt": end}}, function(err, list){
res.render('templates/list',{ layout: false, appointments: list });
});
});
Use the Date() constructor to convert milliseconds to a date, e.g. const date = new Date(timestamp) . The Date() constructor takes an integer value that represents the number of milliseconds since January 1, 1970, 00:00:00 UTC and returns a Date object.
Java Calendar setTimeInMillis() MethodThe setTimeInMillis () method of java. util. Calendar class is used to set the current time in millisecond. The date value to be set is passed as long into this method.
In the Format Cells window, go to the Number tab, select Custom from the Category list, and enter h:mm:ss. 000 in the Type text box. As a result, all of the time values are displayed with milliseconds as decimals.
req.params.date
is a string so you need to convert it to a number before passing it to the Date
constructor. Try this instead:
var start = new Date(Number(req.params.date));
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