How to convert Calendar to Date in Java?
Problem Description :
Write a program in Java that converts Calendar to Date?
Concept :
For converting Calendar to Date we have to use getTime() method of Calendar class that is present in java.util.* package.
Java Program :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javamultiplex.datetime; | |
import java.util.Calendar; | |
import java.util.Date; | |
/** | |
* | |
* @author Rohit Agarwal | |
* @category Date and Time | |
* @problem Convert Calendar to Date. | |
* | |
*/ | |
public class ConvertCalendarToDate { | |
/* | |
* For converting Calender to Date we have to use getTime() method of | |
* Calendar class. | |
*/ | |
public static void main(String[] args) { | |
// Creating Calendar class instance | |
Calendar calendar = Calendar.getInstance(); | |
Date date = calendar.getTime(); | |
System.out.println("Current date : " + date); | |
} | |
} |
Output :
References :
Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.
Tags : Date and Time problems, Conversion problems, Calendar to Date in Java, Solution in Java.
How to convert Calendar to Date in Java?
Reviewed by Rohit Agarwal
on
12/04/2016
Rating:

I must say that www.shinyessays.com/blog/essay-writer-online is a great idea to be considered when your brain is not working efficiently. Choose this option, and you will not regret!
ReplyDelete