I am trying to get future and past dates programatically based on the current time. I am not sure if I am just dumb or I am truly doing something wrong. So I have 2 questions
Does Node.js or the V8 engine have getMinutes, getMonth, etc... in it? I ask because when I try them I get a has no method
errors for each of them with regards to a Date object?
Second question is: is there a resource I have missed on how to deal with dates in Node/V8 that I have just missed somewhere?
At the end of the day I am trying to get a date object that is from an hour ago and an hour into the future. Also 5 minutes ago and 5 minutes in the future. It doesn't seem like it should be that hard, but I have been spinning my wheels for a couple of hours now.
Also do it without a 3rd party javascript module.
Here is one, of many, attempt with little luck:
var d1 = Date();
console.log(d1);
console.log(d1.getMonth());
error:
TypeError: Object Sun May 13 2012 20:28:01 GMT-0500 (CDT) has no method 'getMonth'
Another example this time from REPL: (Should this not be "march 3 2012 at 3:03:03")?
d1 = new Date(2012,3,3,3,3,3)
> Tue, 03 Apr 2012 08:03:03 GMT
When the Date constructor is called as a function, it returns a string, not a date object. Change your code to:
var d1 = new Date();