From this question I get a very useful function, which can calculate the day of the year from a date.
My question is that how can I reverse it?
So when I pass a number to the function's parameter, which is the day of the year, the function returns a date?
Here's the code:
var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
console.log('Day of year: ' + day);