GregorianCalendar « Calendar « Java Data Type Q&A

1. Convert a string to GregorianCalendar

I have a string from an email header, like Date: Mon, 27 Oct 2008 08:33:29 -0700. What I need is an instance of GregorianCalendar, that will represent the same moment. As ...

2. I18n and calendars - Can the calendar system remain as the Gregorian Calendar?

This is a follow up question (and possibly should have been asked before it) to this question: Subclasses of java.util.Calendar. I'm internationalising a large Java app that uses dates fairly regularly ...

3. Java: What/where are the maximum and minimum values of a GregorianCalendar?

What are the maximum and minimum values of a GregorianCalendar? Are they in a constant like Integer.MAX_VALUE, or maybe GregorianCalendar.get(BLAH)? In a nutshell, how can I create a GregorianCalendar instance with min/max value? ...

4. Strange behaviour with GregorianCalendar

I just encountered a strange behaviour with the GregorianCalendar class, and I was wondering if I really was doing something bad. This only appends when the initialization date's month has an actualMaximum ...

5. another strange behaviour with GregorianCalendar

Take a look at the piece of code bellow:

Calendar today1 = Calendar.getInstance();
today1.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);

Calendar today2 = new GregorianCalendar(2010, Calendar.JULY, 14);
today2.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
I'm quite confused... Assuming I am running it today as July 14th, ...

6. XMLGregorianCalendar to GregorianCalendar and back - inconsistent results

Consider the output from the code below with and without the call to get Calendar.HOUR_OF_DAY:

    XMLGregorianCalendar cal = datatypeFactory.newXMLGregorianCalendar("1994-08-10T00:00:00Z");
    System.out.println("Cal: " + cal);


7. Java Calendar Setting Incorrectly

I'm having some trouble with Java's Calendar. I'm parsing some data from a txt file, and need to create a date. After completion of the following code:

tmpYear = Double.parseDouble(row[yearIndex]);
tmpMonth = Double.parseDouble(row[monthIndex]);
tmpDay ...

8. Calendar's GregorianCalendar methods setting date to previous day

I'm having a strange issue with abstract Calendar class using the GregorianCalendar method. For some reason using "calendar.set" is returning a date from the previous day. See code below for example with ...

9. Java: GregorianCalendar returns wrong data

I want to calculate the monday of a specific week number of a year. This is how I do it:

final GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
calendar.set(Calendar.YEAR, 2012); // set to 2012
calendar.set(Calendar.WEEK_OF_YEAR, 20); ...

10. Why does the Date class in Java display a year after subtracting 1900 from it?

Since the Date class in Java was deprecated, I had quite less frequently been using it but when I used it, felt that it might sometimes irritate someone as it displays ...

11. Right way to convert XMLGregorianCalendar to GregorianCalendar

I have 2 classes. First contains Calendar field and Integer field (tz offset). Second contains XmlGregorianCalendar field. I want to compare date from firs class to date from second.

Calendar cal1 = ...

14. GregorianCalendar -- Calendar.SECOND

I think it's really just turning out that way because your statements are being executed so quickly. Because your command take a matter of milliseconds to complete, it's very likely that all 3 Calendar objects will be created at the same second. I added this line after the "new sec();" line: for ( long i = 0; i < 10000000000l; i++ ...

15. Problem in using java.util.Calendar or Gregorian calendar class - Help needed

Dear all, The java.util.Calendar class does not return to me the proper result, when i try to peform the arithmetic manipulations on date like Add or subtract.. Internally, to be a on a more specific note, for the date the gregorian calendar's add method is called. Probable Reason: The probable reason for the above issue is the gregorian calendar internally uses ...

16. Abstract Calendar returns GregorianCalendar?

18. Gregorian Calendar: Calendar.VARIABLE