Day of the Year

EasyMathString

Solution

export function dayOfYear(date: string): number {
  const msOfDay = 24 * 60 * 60 * 1000;
  const currentDate = new Date(date);
  const firstDateOfYear = new Date(currentDate.getFullYear(), 0, 1);
  return Math.floor((currentDate.getTime() - firstDateOfYear.getTime()) / msOfDay) + 1;
}