Start of week for locale using Joda-Time

后端 未结 7 2148
旧时难觅i
旧时难觅i 2020-11-28 10:20

How do you determine which day of the week is considered the “start” according to a given Locale using Joda-Time?

Point: Most countries use the international standard

7条回答
  •  情歌与酒
    2020-11-28 11:01

    I used the following stub in Scala to obtain first and last days of the week from Joda DateTime

    val today: DateTime = new DateTime()
    val dayOfWeek: DateTime.Property = today.dayOfWeek()
    
    val firstDayOfWeek: DateTime = dayOfWeek.withMinimumValue().minusDays(1)
    val lastDayOfWeek: DateTime = dayOfWeek.withMaximumValue().minusDays(1)
    

    Note: The minusDays(1) is only meant to make the week span from Sunday to Saturday (instead of the default Monday to Sunday known to Joda). For US (and other similar) locales, you can ignore this part

提交回复
热议问题