Reputation: 559
I have the following code
{
Calendar mSunday = getToday();
mSunday.add(Calendar.YEAR, 2);
mSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
Calendar mMonday = getToday();
mMonday.add(Calendar.YEAR, 2);
mMonday.add(Calendar.WEEK_OF_YEAR, -1);
mMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
}
public static Calendar getToday() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.AM_PM, 0);
return calendar;
}
I log the dates and my desired output should be
Sun Jun 03 00:00:00 IST 2018
Mon May 28 00:00:00 IST 2018
but when I run the same code in Samsung Note 2, I get the output as
Sun Jun 10 00:00:00 GMT+05:30 2018
Mon May 28 00:00:00 GMT+05:30 2018
Can someone please explain why the difference while using Samsung Note 2 since Calendar is a Java object and should be independent of android version model or whatsoever.
Upvotes: 0
Views: 58
Reputation: 3698
I have worked on calender. You just need to Local in calender object.
Upvotes: 1