-1

I am documenting some code and need help understanding this little line.

private Calendar cal = Calendar.getInstance();
if ((this.cal.get(7) != 7) || (this.cal.get(7) == 1)) {

What does cal.get(7) mean? I ran it on an IDE, and it gave me a result of 5. I tried cal.get(6), and got a result of 169.

Dan Getz
  • 8,774
  • 6
  • 30
  • 64
xem
  • 125
  • 5
  • 17
  • 1
    You should provide more information. For example: declaration of the variable "cal". Also "I did 6 and it gives me 169". What is this "6" you are talking about? – Balkrishna Rawool Jun 18 '15 at 22:50

2 Answers2

3

If "cal" is a java.util.Calendar, then 7 would be DAY_OF_WEEK. However, you shouldn't pass literal integers into the .get() method; use the constants on the Calendar class instead. So, for instance, this is the equivalent of your example:

if ((this.cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) || (this.cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {

(DAY_OF_YEAR has the value of 6, by the way)

The Calendar class has a large number of constants you can use; see the javadoc for more info.

aryn.galadar
  • 716
  • 4
  • 13
  • I was using a decompiler, maybe thats why it was showing these numbers.Don't have the source code. THANKS, btw!!! :D – xem Jun 18 '15 at 23:06
0
/**
     * Field number for <code>get</code> and <code>set</code> indicating the day
     * of the week.  This field takes values <code>SUNDAY</code>,
     * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
     * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
     *
     * @see #SUNDAY
     * @see #MONDAY
     * @see #TUESDAY
     * @see #WEDNESDAY
     * @see #THURSDAY
     * @see #FRIDAY
     * @see #SATURDAY
     */
    public final static int DAY_OF_WEEK = 7;
Carx
  • 1
  • 2