Calendar showing the wrong day of the week

I have a calendar object as shown below that represents 08 Aug 2014

. It's Friday. So there myCal.get(Calendar.DAY_OF_WEEK)

should be 6. But that gives 2. Why?




source to share

2 answers

I have a calendar object as shown below, which represents 08 Aug 2014.

It is not: MONTH=8

- September, not August (month numbering starts at zero).

You can be sure by checking DAY_OF_YEAR=251

in your release. The 251st day of a non-leap year is September 8th .

Another way to check the timestamp is to paste 1410177767000




GregorianCalender takes the month in August, and "7" rather than "8" because January is represented as "0". Reference: Gregorian calendar

So kindly check the following and it should work.

   import java.util.*;

   public class Test {
       public static void main(String args[]) {
           GregorianCalendar myCal = new GregorianCalendar(2014, 7, 8);




All Articles