**The task**
Given a variable of type long with the number of milliseconds from January 1, 1970 until a later date (CurrentDate). Build a class for get the year, month, day of year, day of month, hour, minute and second of the CurrentDate.

**Solution 1:**

```
public class MilisecondToDate {

    public final long MILISECONDS_PER_YEAR = 31536000000L;
    public final long MILISECONDS_PER_DAY = 86400000L;
    public final long MILISECONDS_PER_HOUR = 3600000L;
    public final long MILISECONDS_PER_MINUTE = 60000L;
    public final long MILISECONDS_PER_SECONDS = 1000L;

    public final int FIRST_YEAR = 1970;

    public final int DAY_OF_YEAR_IN_END_OF_JANUARY = 31;
    public final int DAY_OF_YEAR_IN_END_OF_FEBRUARY = 59;
    public final int DAY_OF_YEAR_IN_END_OF_MARCH = 90;
    public final int DAY_OF_YEAR_IN_END_OF_APRIL = 120;
    public final int DAY_OF_YEAR_IN_END_OF_MAY = 151;
    public final int DAY_OF_YEAR_IN_END_OF_JUNE = 181;
    public final int DAY_OF_YEAR_IN_END_OF_JULY = 212;
    public final int DAY_OF_YEAR_IN_END_OF_AUGUST = 243;
    public final int DAY_OF_YEAR_IN_END_OF_SEPTEMBER = 273;
    public final int DAY_OF_YEAR_IN_END_OF_OCTOBER = 304;
    public final int DAY_OF_YEAR_IN_END_OF_NOVEMBER = 334;
    public final int DAY_OF_YEAR_IN_END_OF_DECEMBER = 365;

    private long milisecond;

    public MilisecondToDate(long milisecond) {
        this.milisecond = milisecond;
    }

    public int getYear() {
        return FIRST_YEAR + (int)(milisecond / MILISECONDS_PER_YEAR);
    }

    public int getDayOfYear() {
        long milisecondMinusYears = (milisecond % MILISECONDS_PER_YEAR);
        int dayOfYear = (int) ((milisecondMinusYears + MILISECONDS_PER_DAY)/ MILISECONDS_PER_DAY) - getTotalOfLeapYears();

        return dayOfYear;
    }

    public int getHour() {
        long milisecondMinusYears = (milisecond % MILISECONDS_PER_YEAR);
        long milisecondsMinusDays = (milisecondMinusYears % MILISECONDS_PER_DAY);   

        return (int) ((milisecondsMinusDays + MILISECONDS_PER_HOUR) / MILISECONDS_PER_HOUR);
    }

    public int getMinute() {
        long milisecondMinusYears = (milisecond % MILISECONDS_PER_YEAR);
        long milisecondsMinusDays = (milisecondMinusYears % MILISECONDS_PER_DAY);
        long milisecondsMinusHours = (milisecondsMinusDays % MILISECONDS_PER_HOUR);

        return (int) (milisecondsMinusHours / MILISECONDS_PER_MINUTE);
    }

    public int getSecond() {
        long milisecondMinusYears = (milisecond % MILISECONDS_PER_YEAR);
        long milisecondsMinusDays = (milisecondMinusYears % MILISECONDS_PER_DAY);
        long milisecondsMinusHours = (milisecondsMinusDays % MILISECONDS_PER_HOUR);
        long milisecondsMinusMinutes = (milisecondsMinusHours % MILISECONDS_PER_MINUTE);

        return (int) (milisecondsMinusMinutes / MILISECONDS_PER_SECONDS);
    }

    private int getTotalOfLeapYears() {
        int currentYear = getYear();
        int totalLeapYears = 0;
        for(int year = FIRST_YEAR; year <= currentYear; year++) {
            if(isLeapYear(year)) {
                totalLeapYears += 1;
            }
        }
        return totalLeapYears;
    }

    private int getMonth() {
        int dayOfYear = getDayOfYear();
        int month = 0;
        int leapYear = 0;

        if(isLeapYear(getYear())) {
            leapYear = 1 ;
        }

        if(dayOfYear < DAY_OF_YEAR_IN_END_OF_JANUARY) {
            month = 1;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_FEBRUARY + leapYear)) {
            month = 2;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_MARCH + leapYear)) {
            month = 3;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_APRIL + leapYear)) {
            month = 4;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_MAY + leapYear)) {
            month = 5;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_JUNE + leapYear)) {
            month = 6;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_JULY + leapYear)) {
            month = 7;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_AUGUST + leapYear)) {
            month = 8;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_SEPTEMBER + leapYear)) {
            month = 9;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_OCTOBER + leapYear)) {
            month = 10;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_NOVEMBER + leapYear)) {
            month = 11;
        }else if(dayOfYear < (DAY_OF_YEAR_IN_END_OF_DECEMBER + leapYear)) {
            month = 12;
        }else {
            throw new Error("An error occurred trying to get the day of the month");
        }

        return month;
    }

    private int getDayOfMonth() {
        int dayOfYear = getDayOfYear();
        int month = getMonth();
        int leapYear = 0;

        if(isLeapYear(getYear())) {
            leapYear = 1 ;
        }

        switch (month) {
            case 1:
                break;
            case 2:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_JANUARY; 
                break;
            case 3:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_FEBRUARY - leapYear; 
                break;
            case 4:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_MARCH - leapYear; 
                break;
            case 5:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_APRIL - leapYear; 
                break;
            case 6:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_MAY - leapYear; 
                break;
            case 7:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_JUNE - leapYear; 
                break;
            case 8:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_JULY - leapYear; 
                break;
            case 9:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_AUGUST - leapYear; 
                break;
            case 10:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_SEPTEMBER - leapYear; 
                break;
            case 11:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_OCTOBER - leapYear; 
                break;
            case 12:
                dayOfYear -= DAY_OF_YEAR_IN_END_OF_NOVEMBER - leapYear; 
                break;
            default:
                throw new Error("An error occurred trying to get the day of the month");
        }

        return dayOfYear;
    }

    private boolean isLeapYear(int year) {
        if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))) {
            return true;
        }else {
            return false;
        }
    }

    public String toString() {
        String date = "";

        date += getYear() + "-";
        date += getMonth() + "-";
        date += getDayOfMonth() + " ";

        date += getHour() + ":";
        date += getMinute() + ":";
        date += getSecond();

        return date;
    }

}

```

Any suggestion about the code, any idea that why I did

Any idea why I need to add another hour and a day?