dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Nov 14, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
OCTAVIA ANGHEL
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date