Can I create a date object when the year is not applicable?

I am trying to create a date object that does not have a year, since this is not applicable (it represents the time of year, not a specific year).

I would like to use the actual Date class if possible, since my framework has automatic HTTP binding to this.

There is no constructor for this.

+3
source share
6 answers

It's not clear what you mean by "automatic HTTP binding" - in what context? How will this value be transmitted?

Date, - - 2012, , , 29 . , , , . (, Calendar , , Date, // .., .)

, , Date - a Date , Date . , . , - , . , , .

Joda Time Java. MonthDay ( , ), LocalDate . ReadablePartial , :)

+3

Date month day, , Date .

, Date 2012 , 29 :

public class MyDate extends Date {
    static private final long START = 1325286000000L; // Dec 31st, 2011
    static private final long ONE_DAY = 24 * 60 * 60 * 1000;
    static private final int[] DAYS = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};

    public MyDate(int month, int day) {
        super(START + (DAYS[month - 1] + day) * ONE_DAY);
    }
}
+3

. Date, , ,

+1

, , :

public class YearlessDate{
    private int month;
    private int day;
}
+1

, , , . , joda Partial.

+1

Source: https://habr.com/ru/post/1783446/


All Articles