java SimpleDateFormat

后端 未结 4 1551
甜味超标
甜味超标 2020-12-15 23:51

in Java, how to parse a date string that contains a letter that does not represent a pattern?

\"2007-11-02T14:46:03+01:00\"
String date =\"2007-11-0         


        
4条回答
  •  一个人的身影
    2020-12-16 00:27

    If you don't care about the time zone, you can use this method.

      public static Date convertToDate(String strDate) throws ParseException {
        Date date = null;
        if (strDate != null) {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
          date = sdf.parse(strDate);
        }
        return date;
      }
    

    I don't know if it's still useful for you, but I encounter with the same problem now, and after a little I come up with this.

提交回复
热议问题