Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

String Format Method example using various date formats

Hi,
I am looking for String Format Method example using various date formats
https://www.javatpoint.com/java-string-format.

I found above link but no example there using the date format though like MMDDYYYY or YYYYMMDD etc to represent date?
please advise
SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

import java.text.SimpleDateFormat;
import java.util.Date;

public class FormatExample{  
public static void main(String args[]){  
/*String name="sonoo";  
String sf1=String.format("name is %s",name);  
String sf2=String.format("value is %f",32.33434);  
String sf3=String.format("value is %32.12f",32.33434);//returns 12 char fractional part filling with 0  
  
System.out.println(sf1);  
System.out.println(sf2);  
System.out.println(sf3);  */
	
	 SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
	 Date dateToFormat = new Date() ;
	 String formattedDate = format.format(dateToFormat) ;
	 System.out.println(formattedDate);
}} 

Open in new window

i got right output
20170605
Avatar of dpearson
dpearson

I think we covered it.