Start of week for locale using Joda-Time

后端 未结 7 2077
旧时难觅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

    0 讨论(0)
提交回复
热议问题