get the right Month format date java

前端 未结 2 765
鱼传尺愫
鱼传尺愫 2021-01-27 06:25

can any help, how to get the right date from an String like this \"2014-01-10T09:41:16.000+0000\" my code is:

    String strDate = \"2014-01-10T09:41:16.000+0000         


        
相关标签:
2条回答
  • 2021-01-27 07:11

    The documentation states:

    java.util.Calendar.MONTH

    MONTH public static final int MONTH Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

    -> Counting starts at 0 for Calendar.MONTH

    0 讨论(0)
  • 2021-01-27 07:19

    I think the easiest would be to use another formatter object to do the formatting instead of building it yourself:

    try {
        Date d = new Date(cal.setTimeInMillis(formater.parse(strDate).getTime()));
        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
        String offerDate = format.format(d);
        System.out.println(offerDate);
    } catch (Exception e){
        System.out.println(e.getMessage());
    }
    
    0 讨论(0)
提交回复
热议问题