Question:
(JAVA) How do I convert from GregorianCalendar to Date?
Know It All
2008-05-22 09:07:30 UTC
I have the following code:

today = new Date();
threeMonthsAgo = new Date();

temp = new java.util.GregorianCalendar();
temp.add(java.util.Calendar.MONTH, -3);

I want to assign the value of temp to threeMonthsAgo.

How do I convert the GregorianCalendar temp to a Date object?
Three answers:
anonymous
2008-05-22 12:18:02 UTC
I don't know why they decided to call it this but,

threeMonthsAgo = temp.getTime();
dakins
2016-09-30 15:11:23 UTC
Java Gregoriancalendar
anonymous
2016-04-07 04:44:47 UTC
For the best answers, search on this site https://shorturl.im/av7IV



For form entry you may have noted date is either a graphical calendar widget or it is 3 JCombo selectors because some cultures list dd/mm/yyyy while others describe it as mm,dd,yy. The other problem is the time calculation in Java API is months are indexed as '0' for January thru '11' for December. Thus the reason why you see so much widget tools to get the time format correct. it is easy math if from there we convert to milliseconds into type long to do any date manipulation. The Java API will convert the millieseconds back with precision into the human calendar. class Calendar is abstract, you use it indirectly, then set the created Object to the time you want. class GregorianCalendar extends Calendar with 50 options available. Time is tricky for many programmers because they don't realize Time is a human invention.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...