Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

&nbsp;
Example 1:

Input: date = "2019-01-09"
Output: 9
Explanation: Given date is the 9th day of the year in 2019.


Example 2:

Input: date = "2019-02-10"
Output: 41


&nbsp;
Constraints:


	date.length == 10
	date[4] == date[7] == '-', and all other date[i]'s are digits
	date represents a calendar date between Jan 1st, 1900 and Dec 31th, 2019.


class Solution:
    def dayOfYear(self, date: str) -> int:
        d={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
        year=int(date[:4])
        if year%4==0:
            if year%100==0:
                if year%400==0:
                    d[2]=29
            else:
                d[2]=29
        month=int(date[5:7])
        day=int(date[8:])
        ans=0
        for i in range(1,month+1):
            ans+=d[i]
        return ans-(d[month]-day)
class Solution {
    public int dayOfYear(String date) {
        int days = 0;
        int[] arr = {31,28,31,30,31,30,31,31,30,31,30,31};
        String[] year = date.split("-");
        int y = Integer.valueOf(year[0]);
        int month = Integer.valueOf(year[1]);
        int day = Integer.valueOf(year[2]);
        boolean leap = false;
        for(int i = 0; i < month-1; i++){
            days = days+arr[i];
        }
        days = days+day;
        if(y%4==0){
            if(y%100==0){
                if(y%400==0){
                    leap = true;
                }
                else{
                    leap = false;
                }
            }
            else{
                leap = true;
            }
        }
        else{
            leap = false;
        }
        if(leap==true && month>2){
            System.out.println("Leap Year");
            days = days+1;
        }
        return days;
    }
}
class Solution {
public:
    bool leapyear(int year){
        return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    }
        
    int dayOfYear(string date) {
        vector<int> v;
        int ans = 0;
        int n = date.length();
        for (int i = 0; i < n; i++) {
            if (date[i] >= '0' && date[i] <= '9') {
                ans = ans * 10 + (date[i] - '0'); // subtract '0' to get the integer value
            } else {
                v.push_back(ans);
                ans = 0;
            }
        }
        v.push_back(ans); // add the last value to the vector
        if (v.size() != 3) return -1; // error handling for invalid input
        int year = v[0];
        int month = v[1];
        int day = v[2];
        if (month == 1) return day;
        if (month == 2) return 31 + day;
       
        if (month == 3) return leapyear(year) ? 60 + day : 59 + day;
         if (month == 4) return leapyear(year) ? 91 + day : 90 + day;
         if (month == 5) return leapyear(year) ? 121 + day : 120 + day;
         if (month == 6) return leapyear(year) ? 152 + day : 151 + day;
         if (month == 7) return leapyear(year) ? 182 + day : 181 + day;
         if (month == 8) return leapyear(year) ? 213 + day : 212 + day;
         if (month == 9) return leapyear(year) ? 244 + day : 243 + day;
         if (month == 10) return leapyear(year) ? 274+ day : 273 + day;
         if (month == 11) return leapyear(year) ? 305 + day : 304 + day;
         if (month == 12) return leapyear(year) ? 335 + day : 334 + day;
        return -1;
    }
};
var dayOfYear = function(date) {
    let dat2 = new Date(date)
    let dat1 = new Date(dat2.getFullYear(),00,00)
    let totalTime = dat2 - dat1
    return Math.floor(totalTime/1000/60/60/24)
};
Day of the Year