How to return an object, calculating dates?

8

I'm calculating the difference between dates in a period. From today until previous days:

hoje = new Date();
periodo = new Date().setDate(hoje.getDate() - 5);

This way the output is as follows:

Fri Sep 19 2014 17:05:11 GMT-0300 (Local Standard Time)
1409861111749 

I want the calculated date also to return as an object:

Fri Sep 14 2014 17:05:11 GMT-0300 (Local Standard Time) 
    
asked by anonymous 19.09.2014 / 22:09

1 answer

8

You can create a new date from the timestamp returned by the setDate operation:

periodo = new Date(new Date().setDate(hoje.getDate() - 5))

According to the language specification , setDate always returns a TimeClip, which represents the number of milliseconds from 1st. January 1970 (UTC) to the date in question.

    
19.09.2014 / 22:13