1

The Unix timestamp is 1417029117, which is 11/26/2014, Wednesday.

long timestamp = 1417029117l*1000l;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
System.out.println("current day is "+cal.get(Calendar.DAY_OF_WEEK));
System.out.println("current month is "+cal.get(Calendar.MONTH));

And I got the results as follows:

current day is 4
current month is 10

Any explanation? If January is 0 then the month is fine. But why the day is 4?

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
chrisTina
  • 2,298
  • 9
  • 40
  • 74
  • 1
    possible duplicate of [Unsure what get(Calendar.DAY\_OF\_WEEK) returns](http://stackoverflow.com/questions/10931152/unsure-what-getcalendar-day-of-week-returns) –  Nov 26 '14 at 19:24

1 Answers1

1

First day of the week is Sunday. So, Wednesday is 4. See Calendar#DAY_OF_WEEK and Constant Field Values, Calendar#WEDNESDAY, it's plain out there in the documentation.

Christian Hujer
  • 17,035
  • 5
  • 40
  • 47
  • I am still curious, why does `cal.get(Calendar.WEDNESDAY)` returns `5`? – chrisTina Nov 26 '14 at 19:31
  • Ouch! Why are you passing `Calendar.WEDNESDAY` into `cal.get()`? What should be the meaning of that? "Tell me the Wednesday of the given timestamp?" It's not made for that. `Calendar.WEDNESDAY` is 4. `Calendar.WEEK_OF_MONTH` also is 4. `cal.get(Calender.WEDNESDAY)` is the same as `cal.get(Calendar.WEEK_OF_MONTH)`, and it's the 5th week of the month. – Christian Hujer Nov 26 '14 at 19:36