How do I calculate the year from (new Date).getTime()

This should be simple math buy I just can't deduce it at the moment. getTime() should return a unix time stamp in milli-seconds and from there one should be able to figure out the year.

function theYear(timestamp){
    // answer
    return year;
}

Upvotes: 0

Views: 83

Answers (2)

Jens A. Koch
Jens A. Koch

Reputation: 41737

function theYear(timestamp){    
    return new Date(timestamp).getYear();
}

Upvotes: 0

kamituel
kamituel

Reputation: 35950

It should be:

 var year = new Date(timestamp).getFullYear();

Upvotes: 3

Related Questions