How to convert date and time in string to Date object in Java

1 Answer

0 votes
import java.text.SimpleDateFormat;  
import java.util.Date; 
 
public class MyClass {
 
    public static void main(String args[]) throws Exception {  
        String dateString = "2023-10-10T09:47:03.000Z";
         
        Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(dateString);  
         
        System.out.println(date);  
    }
}
         
         
         
         
/*
run:
         
Tue Oct 10 09:47:03 GMT 2023
 
*/

 



answered Oct 8, 2023 by avibootz
edited Oct 8, 2023 by avibootz

Related questions

1 answer 125 views
1 answer 84 views
1 answer 116 views
1 answer 103 views
1 answer 149 views
...