Parsing date with Joda API

后端 未结 2 692
时光说笑
时光说笑 2021-01-25 02:59

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(         


        
2条回答
  •  余生分开走
    2021-01-25 03:50

    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.
    

提交回复
热议问题