get the right Month format date java

前端 未结 2 767
鱼传尺愫
鱼传尺愫 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: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());
    }
    

提交回复
热议问题