How to extract a date from a string and put it into a date variable in Java

前端 未结 5 1542
日久生厌
日久生厌 2020-12-19 20:39

I have been looking around stack-overflow and various other websites for the solution to my problem but haven\'t found any suitable for my specific purposes and have been un

5条回答
  •  不思量自难忘°
    2020-12-19 21:39

    You could use parse like this:

    String fromDate = "2009/05/19";
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    java.util.Date dtt = df.parse(fromDate);
    

    this turns any(well formatted) string into a date variable.

    the code is from here

提交回复
热议问题