devxlogo

Converting a Date to a Certain String Format

Converting a Date to a Certain String Format

The format() method from SimpleDateFormat class helps to convert a Date object into certain format String objects by using the supplied pattern string.

Date today = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy"); //pattern is specified here System.out.println(dateFormat.format(today)); //30-Aug-18 Patterns can be applied again by using applyPattern() dateFormat.applyPattern("dd-MM-yyyy"); System.out.println(dateFormat.format(today)); //30-08-2018 dateFormat.applyPattern("dd-MM-yyyy HH:mm:ss E"); System.out.println(dateFormat.format(today)); //30-08-2018 16:26:41 Thu
See also  Java Developer Jobs: Your Guide to Landing the Perfect Position in 2024
devxblackblue

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