Get all full hours of every day of a year

前端 未结 3 1730
青春惊慌失措
青春惊慌失措 2021-01-20 23:04

I need to get / print on command line every full hour of every day of a given year, e.g. 2011 but I am struggling to code it in Java.

Has anybody ever coded this issue?

3条回答
  •  佛祖请我去吃肉
    2021-01-20 23:33

    you could easily solve this by using the joda-time library:

        org.joda.time.Hours.hoursBetween(
            new org.joda.time.DateMidnight(2012,1,1).toLocalDate(), 
            new org.joda.time.DateMidnight(2013,1,1).toLocalDate()
          ).getHours();
    

提交回复
热议问题