Hey guys in this short article, you will learn how to convert the current date and time to String format in Java.
Read More:
- Check the Complete Spring MVC Tutorials
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
To convert Date to String format, we can call toString()
method on the Date()
object
currentDateAndTime.toString();
Example
The following example demonstrates converting the current date and time to String format.
public class ConvertDateToString {
public static void main(String[] args) {
//Get the current date and time
Date currentDateAndTime = new Date();
//Convert the date and time to string using toString()
System.out.println(currentDateAndTime.toString());
}
}
Output:
Mon Jan 03 15:57:51 IST 2022
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.