How to convert String date to Date?

后端 未结 3 1952
北恋
北恋 2021-01-29 10:02

I have done following code:

String str = \"2013-01-17 11:26\";
DateFormat dateFormat = new SimpleDateFormat(\"yyyy-mm-dd hh:MM\");
Date date = dateFormat.parse(s         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 10:38

    The following code should work well:

    try{
    String str = "2013-01-17 11:26";
    DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm");
    Date date = (Date)dateFormat.parse(str);
    System.out.println("str :"+str);
    System.out.println("Date :"+date);
    }
    catch(Exception e){
       e.getStackTrace();
    }
    

提交回复
热议问题