Java Convert Date to String format dd/mm/yyyy




Hey guys in this short article, you will learn how to convert the current date and time to different formats in String

Read More:

To convert Date to different formats in String we will use SimpleDateFormat() object.

SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");

Convert date to dd/MM/yyyy format


public class FormatDate {
	
	public static void main(String[] args) {
		
		Date date = new Date();
		
		SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
		
		System.out.println(formatDate.format(date));
	}
}

Output:

03/01/2022

Convert date to dd/MM/yyyy hh:mm:ss format


public class FormatDate {
	
	public static void main(String[] args) {
		
		Date date = new Date();
		
		SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
		
		System.out.println(formatDate.format(date));
	}
}

Output:

03/01/2022 04:15:34

That’s it for this post, if you like this post, share this with your friends and colleagues or you can share this within your social media platform. Thanks, I will see you in our next post.



Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply