Calendar.MONTH gives wrong value
Keep in mind that months values start from 0
, so October
is actually month number 9
.
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Calendar.html#MONTH
Java Calendar giving wrong value after parsing month string
You should instantiate your Calendar
with appropriate locales:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"),Locale.US);
Calendar returns wrong month and year Java
Those are all static
fields from the Calendar
class. Java allows static
fields (and methods) to be accessed on expressions that resolve to an instance's reference value the same way it does on type names
now.ERA
// is equivalent to
Calendar.ERA
The Calendar
class provides a get(int)
method for getting the value of a date field.
now.get(Calendar.MONTH);
Calendar.MONTH setting to wrong month
Because today's date is the 31st of August and June only has 30 days, the month is automatically incremented to the following month giving July.
To solve you can set the date before setting the month
c.set(Calendar.DATE, 30);
c.set(Calendar.MONTH, Calendar.JUNE);
Also I suggest using Calendar
constants for clarity
Related Topics
Overriding Object.Equals VS Overloading It
Custom Objectmapper with Jersey 2.2 and Jackson 2.1
List All Files in the Folder and Also Sub Folders
Advantage of Set and Get Methods VS Public Variable
Class Object of Generic Class (Java)
Is Concurrenthashmap Totally Safe
Can a Private Method in Super Class Be Overridden in the Sub-Class
How to Attach Multiple Files to an Email Using Javamail
Maximum Size of Hashset, Vector, Linkedlist
What Is the Most Accurate Encoding Detector