GregorianCalendar

  • Thread starter Andreas N Rasmussen
  • Start date
A

Andreas N Rasmussen

Howdy,

I'm having some trouble with the GregorianCalendar subclass of
Calendar. My goal is to be able to properly determine the DAY_OF_WEEK
of any date back to year 1. The problem is that GregorianCalendar is
too smart, and returns the Julian Calendar response instead. I know
this is how it is in the real world, but i need the corresponding day
in the Gregorian Calendar to be able to check an assignment.

There is a method myCal.setGregorianChange(Date date) for just this
problem, but I cant seem to be able to call it with a Calendar, and
Date is deprecated... What do I do?

Thank you in advance...

Andreas N Rasmussen

"When you think about it - mud is nothing but wet dirt"
- Homer Simpson
 
M

Michael Borgwardt

Andreas said:
There is a method myCal.setGregorianChange(Date date) for just this
problem, but I cant seem to be able to call it with a Calendar,

No, of course not. It is not a subclass of Date.
and Date is deprecated...

No, it is not. You seem to mistakenly believe that Calendar replaces Date.
It does not. Date is still to be used for representing a date, i.e. a point
in time. Calendar was introduced to allow a flexible and powerful method
of converting a Date to a corresponding representation in a system of
reckoning as year, month and day. Since these systems have various oddities
and irregularities, this is a nontrivial taks and thus was given its own
class.
 
T

Thomas Weidenfeller

There is a method myCal.setGregorianChange(Date date) for just this
problem, but I cant seem to be able to call it with a Calendar, and
Date is deprecated... What do I do?

Date is not deprecated.

/Thomas
 
D

Dario

Andreas said:
I'm having some trouble with the GregorianCalendar subclass of
Calendar. My goal is to be able to properly determine the DAY_OF_WEEK
of any date back to year 1. The problem is that GregorianCalendar is
too smart, and returns the Julian Calendar response instead. I know
this is how it is in the real world, but i need the corresponding day
in the Gregorian Calendar to be able to check an assignment.

There is a method myCal.setGregorianChange(Date date) for just this
problem, but I cant seem to be able to call it with a Calendar, and
Date is deprecated... What do I do?

Date is *not* deprecated.

Specification of setGregorianChange
<http://makeashorterlink.com/?T225164B6> says:

...
To obtain a pure Gregorian calendar, set the change date
to Date(Long.MIN_VALUE).
...

So, if myGregorialCalendar is your GregorialCalendar
then you may invoke the following method:

myGregorialCalendar.setGregorianChange(new Date(Long.MIN_VALUE));

- Dario
 
T

Thomas Schodt

No, it is not. You seem to mistakenly believe that Calendar replaces
Date.

I think he probably used Date(int,int,int) which is deprecated
and understood the compiler message to mean Date was deprecated.

The following works for me (and compiles without warnings)

Calendar a = Calendar.getInstance(); a.set(year,month-1,day);
((GregorianCalendar)a).setGregorianChange(
new Date(-1970L*366*24*3600*1000L));
System.out.println(a.get(Calendar.DAY_OF_WEEK));
 
P

P.Hill

Andreas said:
Howdy,

I'm having some trouble with the GregorianCalendar subclass of
Calendar. My goal is to be able to properly determine the DAY_OF_WEEK
of any date back to year 1. The problem is that GregorianCalendar is
too smart, and returns the Julian Calendar response instead. I know
this is how it is in the real world, but i need the corresponding day
in the Gregorian Calendar to be able to check an assignment.

There is a method myCal.setGregorianChange(Date date) for just this
problem, but I cant seem to be able to call it with a Calendar, and
Date is deprecated... What do I do?

Thank you in advance...

What are you calculating two dates in 1582? Or maybe you
are trying to work out the Eastern Orthodox Eastern date? :)

Sorry, but GregorianCalendar is supposed to return values in
the *Current* calendar and regardless of Gregorian or Julian
some date n days ago was on the same day of the week regardless
if someone calls it January 3 or January 15th.

Can you provide some code to help me sort out your problem.
I'd be glad to help.
-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top