我有一个字符串,其中包含“1985年12月25日”的日期。如何使用Joda API解析它?
DateTime dt = new DateTime("25 December 1985");
System.out.println(dt.getDayOfWeek());
我需要一周的一天。
答案 0 :(得分:4)
试试这个:
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd MMMM YYYY").withLocale(Locale.ENGLISH);
DateTime dt = dtf.parseDateTime("25 December 1985");
System.out.println(dt.getDayOfWeek());
答案 1 :(得分:1)
参考http://joda-time.sourceforge.net/userguide.html
<强> getDayOfWeek()强>
int iDoW = dt.getDayOfWeek();
其中iDoW可以获取值(来自类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;
或 dayOfWeek()
DateTime.Property pDoW = dt.dayOfWeek();
String strST = pDoW.getAsShortText(); // returns "Mon", "Tue", etc.
String strT = pDoW.getAsText(); // returns "Monday", "Tuesday", etc.