dcsimg
 

Submitted by: OCTAVIA ANGHEL(OCTAVIAANGHEL@GMAIL.COM)

Wednesday Nov 14th 2018 by OCTAVIA ANGHEL

Language: Java, Expertise: Beginner - Convert a date object into certain format string objects using the supplied pattern string.

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
Home
Mobile Site | Full Site