Custom date format cannot be parsed. (Java)

后端 未结 4 949
遇见更好的自我
遇见更好的自我 2020-12-11 16:53

I have to use a custom date format in Java. It contains microseconds although Java doesn\'t provide support for microseconds. Because of that I filled the time pattern with

4条回答
  •  执笔经年
    2020-12-11 16:53

    In addition to jarnbjo's answer, if you need the microseconds, you might be able to use java.sql.Timestamp:

    Date dateToMillis = format.parse(theDate.substring(0, 23));
    DateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    Timestamp timestamp = Timestamp.valueOf(timestampFormat.format(dateToMillis) + theDate.substring(23,26));
    

提交回复
热议问题