How to get start and end date of a year?

前端 未结 15 1779
清酒与你
清酒与你 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:23

    val instance = Calendar.getInstance()
                    instance.add(Calendar.YEAR,-1)
    
     val prevYear = SimpleDateFormat("yyyy").format(DateTime(instance.timeInMillis).toDate())
    
    val firstDayPreviousYear = DateTime(prevYear.toInt(), 1, 1, 0, 0, 0, 0)
    
    val lastDayPreviousYear = DateTime(prevYear.toInt(), 12, 31, 0, 0, 0, 0)
    

提交回复
热议问题