long dayMillies = 86400000; // no. of milliseconds per 1 day
// String to Date Convertion; selectedDate=2012-11-27 // YYYY-MM-DD
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(selectedDate.substring(8, 10)));
c1.set(Calendar.MONTH, Integer.parseInt(selectedDate.substring(5, 7)) - 1);
c1.set(Calendar.YEAR, Integer.parseInt(selectedDate.substring(0, 4)));
// // System.out.println("SSSS: " + c1.getTime());
Date d = c1.getTime();
if (nextDay) {
// next day
d.setTime(d.getTime() + dayMillies);
} else {
// previous day
d.setTime(d.getTime() - dayMillies);
}
Calendar c = Calendar.getInstance();
c.setTime(d);
int Curr_day = c.get(Calendar.DAY_OF_MONTH);
int Curr_month = (c.get(Calendar.MONTH) + 1);
int Curr_year = c.get(Calendar.YEAR);
String day = "" + Curr_day;
String Month = "" + Curr_month;
String Year = "" + Curr_year;
if (Curr_day < 10) {
day = "0" + Curr_day;
}
if (Curr_month < 10) {
Month = "0" + Curr_month;
}
// String time = day + "-" + Month + "-" + Year;
String time = Year + "-" + Month + "-" + day;
// System.out.println("Next date:" + time);
return time;
}
No comments:
Post a Comment