Unsure what get(Calendar.DAY_OF_WEEK) returns

风流意气都作罢 提交于 2019-12-06 11:20:10
Kees de Kooter

The month in java Calendar classes is 0-based. So June is month number 5.

You actually created an object representing July 4th, which happens to be a Wednesday, which is the fourth day of that week.

One should always look for values returned by Calendar.{field} e.g. like Calendar.SUNDAY, Calendar.MONDAY, Calendar.JANUARY, Calendar.MARCH etc. and so on. This is because, the values returned by Calendar.{field} depends upon the TimeZone specified while creating Calendar instance. You can try this by creating two calendar instances with different timezones:

Calendar.getInstance("BST")

and

Calendar.getInstance() // default timezone

and now try getting calendar.get(Calendar.DAY_OF_WEEK) which will return different integer values for these two instances.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!