使用Joda API解析日期

时间:2013-11-20 14:30:17

标签: java parsing jodatime

我有一个字符串,其中包含“1985年12月25日”的日期。如何使用Joda API解析它?

DateTime dt = new DateTime("25 December 1985");
System.out.println(dt.getDayOfWeek());

我需要一周的一天。

2 个答案:

答案 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.