Parsing date with Joda API

后端 未结 2 653
时光说笑
时光说笑 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:43

    Try this:

    DateTimeFormatter dtf = DateTimeFormat.forPattern("dd MMMM YYYY").withLocale(Locale.ENGLISH);
    DateTime dt = dtf.parseDateTime("25 December 1985");
    System.out.println(dt.getDayOfWeek());
    
    0 讨论(0)
  • 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.
    
    0 讨论(0)
提交回复
热议问题