Convert calendar to date in java [2021]
In this tutorial, we will cover how to convert calendar to date in Java, Calendar class has static method Calendar.getInstance().getTime() which will give date class instance.
Calendar to date in Java
import java.util.Calendar;
import java.util.Date;
public class CalendarToDate {
public static void main(String[] args) {
//Creating calendar instance
Calendar cal = Calendar.getInstance();
//Converting calendar to date
Date date = cal.getTime();
//Output : Tue Jun 15 20:22:07 IST 2021
System.out.println(date);
}
}
Output:
Tue Jun 15 20:22:07 IST 2021
Conclusion
In this tutorial, We have covered how to convert Calendar instance to date instance.
Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you have any questions, doubts, suggestions, or feedback then please drop a comment and I'll try to answer your question.
So what do you think about this simple process to Convert calendar to date In Java? It's Easy Right?
Comments
Post a Comment
If you have any doubts, Please let me know.