Reputation: 283
I want to get current month from Calendar.
I used two ways: First:
int gcmonth = Calendar.getInstance().get(Calendar.MONTH);
Second:
Calendar c = (Calendar)Calendar.getInstance();
int gcmonth = c.get(Calendar.MONTH);
Both ways returns 2 (March), but I want to get 8 (September - current month).
EDIT: The date on my phone is right! September 12, 2013 23:32 (Kyiv time)
Upvotes: 2
Views: 1848
Reputation: 1319
SimpleDateFormat sdfDate = new SimpleDateFormat("MM", Locale.getDefault());
String currentDate = sdfDate.format(new Date());
This is it. It will return 09. September.
Upvotes: 0
Reputation: 11314
Check your Phone date it will receive date from your device and will give the output
Calendar c = (Calendar)Calendar.getInstance();
int gcmonth = c.get(Calendar.MONTH);
this also returns 8
Calendar.getInstance().get(Calendar.MONTH);
There is no issue with your code only it is due to Device date
Upvotes: 2