How do I discover the Quarter of a given Date?

前端 未结 14 1198
小鲜肉
小鲜肉 2020-12-24 05:37

Given a java.util.Date object how do I go about finding what Quarter it\'s in?

Assuming Q1 = Jan Feb Mar, Q2 = Apr, May, Jun, etc.

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 06:26

    with java8 you may use formatter:

    import java.time.format.DateTimeFormatter
    import java.time.LocalDate
    
    println("withQuarter: " + LocalDate.of("2016".toInt,"07".toInt,1).format(DateTimeFormatter.ofPattern("yyyyQMM")))
    

    withQuarter: 2016307

提交回复
热议问题