override first day of the week in joda?

感情迁移 提交于 2019-12-10 15:21:52

问题


Is it possible to override the firstday of Joda week to sunday ? since Joda uses Monday as its firstday of the week . Can any one please explain me if there is a way .

I referred the below Topic in SOF

Joda Time: First day of week?

Thanks


回答1:


No.

First of all, overriding the first day of the week to sunday would require overwriting all other weekdays as well. But these final constants are defined in the class DateTimeConstants, which are impossible to overwrite. But you wouldn't want to override theses values anyways because it would mess up joda-time's ISO-compliance.

At the same time I wonder why you would want to override it in the first place? Can you provide a use case?

public static DateTime getUSFirstDayOfWeek(DateTime dateTime) {
    return dateTime.withDayOfWeek(DateTimeConstants.MONDAY).minusDays(1);
}

This simple helper method would probably do the job. Notice that I didn't use SUNDAYbecause it would be in the future, which is - in US notion - the next week already.



来源:https://stackoverflow.com/questions/13602096/override-first-day-of-the-week-in-joda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!