JSFiddle - React, Tailwind, and code Playground
JavaScript
function dayInYear(dateString) {
var now = new Date(dateString);
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);
alert('For the date string \'' + dateString + '\' this script calculated it\'s day ' + day + ' of the year');
}
// The two following calls show that even though the dates are the same, the day of Year are different.
dayInYear('2017-05-01 00:59:59');
dayInYear('2017-05-01 01:00:00');