0

I want to get the timestamp of one-year from now:

var oneYr = new Date();
oneYr.setYear((new Date()).getYear() + 1);

When I try to get the timestamp:

oneYr.getTime() /1000

I get -58351759111000 (not correct)

It's only working for date in the past.
Any idea how to get timestamp for future date?

cheziHoyzer
  • 4,803
  • 12
  • 54
  • 81

1 Answers1

0

Use getFullYear instead of getYear.

var oneYr = new Date();
oneYr.setYear((new Date()).getFullYear() + 1);
Gangadhar Gandi
  • 2,162
  • 12
  • 19
  • This should use the *setFullYear* method. The brackets around `(new Date())` are redundant. Also need to deal with 29 Feb + 1 year. It will roll over to 1 Mar, which may nor may not suit. – RobG Nov 28 '19 at 01:30