我有一个问题来计算星期几,用JodaTime的整个名单。 Pratically,我希望看到基于区域设置一个类似的输出:
1 day: Sunday
2 day: Monday
3 day: Tuesday
4 day: Wednesday
5 day: Thursday
6 day: Friday
7 day: Saturday
我能怎么做?我在JodaTime库是新...
谢谢!
从乔达时间userguide:
举例来说,直接的方式来获得星期特定日期时间,包括调用方法
int iDoW = dt.getDayOfWeek();
where iDoW can take the values (from class DateTimeConstants).
public static final int MONDAY = 1;
public static final int TUESDAY = 2;
public static final int WEDNESDAY = 3;
public static final int THURSDAY = 4;
public static final int FRIDAY = 5;
public static final int SATURDAY = 6;
public static final int SUNDAY = 7;
...
Localized versions of these methods are also available, thus
DateTime.Property pDoW = dt.dayOfWeek();
String strTF = pDoW.getAsText(Locale.FRENCH); // returns "Lundi", etc.
编辑如果使用默认语言环境
DateTime.Property pDoW = dt.dayOfWeek();
String strTF = pDoW.getAsText(Locale.getDefault());
看起来像DateTimeFormat工作
我将开始
DateTime dt = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("EEEE"); // use 'E' for short abbreviation (Mon, Tues, etc)
String strEnglish = fmt.print(dt);
String strFrench = fmt.withLocale(Locale.FRENCH).print(dt);
String strWhereverUR = fmt.withLocale(Locale.getDefault()).print(dt);
并从那里