Use SimpleDateFormatter for Date and Text Conversion

Use SimpleDateFormatter for Date and Text Conversion

The following code shows you how to use SimpleDateFormatter for date and text conversion:

java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("EEE MMM d hh:mm:ss yyyy");		java.util.Date date1 = null;try{   date1 = formatter.parse("Thu Jun 3 09:09:30 2004");}catch(Exception e){   e.printStackTrace();}System.out.println("Date1 in millis : " + date1.getTime());System.out.println("Date1 in string : " + date1);java.util.Date date2 = new java.util.Date(date1.getTime());System.out.println("Date2 in string : " + date2);

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist