How to get start and end date of a year?

前端 未结 15 2018
清酒与你
清酒与你 2021-02-05 02:57

I have to use the Java Date class for this problem (it interfaces with something out of my control).

How do I get the start and end date of a year and then

15条回答
  •  我寻月下人不归
    2021-02-05 03:11

    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTime(start);
    while (gcal.getTime().before(end)) {
        gcal.add(Calendar.DAY_OF_YEAR, 1);
        //Do Something ...
    }
    

    The GregorianCalendar creation here is pointless. In fact, going through Calendar.java source code shows that Calendar.getInstance() already gives a GregorianCalendar instance.

    Regards, Nicolas

提交回复
热议问题