Parsing date with Joda API

2020-04-18 06:33发布

I have a string which contains a date "25 December 1985". How to parse it using Joda API?

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

I need to get a day of week.

2条回答
疯言疯语
2楼-- · 2020-04-18 07:11

Try this:

DateTimeFormatter dtf = DateTimeFormat.forPattern("dd MMMM YYYY").withLocale(Locale.ENGLISH);
DateTime dt = dtf.parseDateTime("25 December 1985");
System.out.println(dt.getDayOfWeek());
查看更多
一夜七次
3楼-- · 2020-04-18 07:21

With reference to http://joda-time.sourceforge.net/userguide.html

getDayOfWeek()

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;

or dayOfWeek()

DateTime.Property pDoW = dt.dayOfWeek();
String strST = pDoW.getAsShortText(); // returns "Mon", "Tue", etc.
String strT = pDoW.getAsText(); // returns "Monday", "Tuesday", etc.
查看更多
登录 后发表回答