How to format a date String into desirable Date format

前端 未结 5 1075
南旧
南旧 2021-01-22 17:11

I was trying to format a string into date.

For this I have written a code:-

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateF         


        
5条回答
  •  走了就别回头了
    2021-01-22 17:33

    This should do it for you, remember to wrap it in a try-catch block just in case.

    DateFormat dt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 
    try
    {
    Date today = dt.parse("2010-10-22T00:00:00");                       
    System.out.println("Your Date = " + dt.format(today));       
    } catch (ParseException e)    
    {
    //This parse operation may not be successful, in which case you should handle the ParseException that gets thrown.
    //Black Magic Goes Here
    } 
    

提交回复
热议问题