How to parse string into Date in Java

1 Answer

0 votes
import java.text.SimpleDateFormat; 
import java.util.Date;
import java.text.ParseException;

public class MyClass {
    public static void main(String args[]) {
      SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); 
      String s = "2021-03-24";

      try {
            Date dt = ft.parse(s); 
		    System.out.println(dt);    

      } catch (ParseException e) { 
            e.printStackTrace();
        }
    }
}



/*
run:

Wed Mar 24 00:00:00 GMT 2021

*/

 



answered Mar 24, 2021 by avibootz

Related questions

1 answer 201 views
2 answers 124 views
124 views asked Oct 8, 2023 by avibootz
4 answers 296 views
1 answer 138 views
2 answers 175 views
175 views asked Mar 20, 2017 by avibootz
...