java.time.LocalDate.getDayOfWeek()到java.util.Calendar.get(DAY_OF_WEEK) [英] java.time.LocalDate.getDayOfWeek() to java.util.Calendar.get(DAY_OF_WEEK)

查看:430
本文介绍了java.time.LocalDate.getDayOfWeek()到java.util.Calendar.get(DAY_OF_WEEK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最近的java.time包,尤其是 LocalDate的星期几获取.

I am using the recent java.time package and in particular the day of week getter of LocalDate.

我得到一个很好的 DayOfWeek 枚举调用LocalDate.getDayOfWeek()时.

I get a nice DayOfWeek enum when calling LocalDate.getDayOfWeek().

但是,我的代码应该与使用日历工作日的整数值(即从代码Calendar.get(DAY_OF_WEEK)获得的)的应用程序的某些较早部分兼容.

However, my code should be compatible with some older part of the application that uses the integer value of a Calendar weekday, i.e. obtained from the code Calendar.get(DAY_OF_WEEK).

很显然,在DayOfWeek枚举中, SUNDAY值是7 ,在日历DAY_OF_WEEK"字段中,

Obviously, in the DayOfWeek enum, SUNDAY value is 7, and in Calendar DAY_OF_WEEK field, SUNDAY value is 1.

那么,我必须选择哪种才能将其转换为另一种?我应该将java.util.Date中的LocalDate转换为Calendar吗?

So, what choices do I have to convert one into another? Should I convert the LocalDate in java.util.Date and then into a Calendar?

推荐答案

WeekFields 类(用于 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆