Skip to content Skip to sidebar Skip to footer

Override First Day Of The Week In Joda?

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

Solution 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.

Post a Comment for "Override First Day Of The Week In Joda?"