Java in a lot of time format, in the solution, more convenient to call
1, the next day to solve
public static string Getnextday (string now) {
Date nowdate;
String Nday=new string ();
SimpleDateFormat sdf=new SimpleDateFormat ("YyyyMMdd");
try{
Nowdate=sdf.parse (now);
Long oneday=1000*3600*24;
Date Nextday=new Date (Nowdate.gettime () +oneday);
Nday = Sdf.format (Nextday.gettime ());
} catch (Exception e) {
e.printstacktrace ();
}
return nday;
}
The main use is the date type in Java to get the number of milliseconds
2. Solve a week
public static string Getnextweek (string now) {
Date nowdate;
String Nweek=new string ();
SimpleDateFormat sdf=new SimpleDateFormat ("YyyyMMdd");
try{
Nowdate=sdf.parse (now);
Long oneday=1000*3600*24;
Date Nextweek=new Date (Nowdate.gettime () +oneday* (9-nowdate.getday ()));
Nweek = Sdf.format (Nextweek.gettime ());
} catch (Exception e) {
e.printstacktrace ();
}
return nweek;
}
3, solve the next one months
public static string Getnextmonth (string now) {
Date t;
String Nmonth=new string ();
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyymm");
try{
T=sdf.parse (now);
Date Nextmonth=new Date ((T.getyear () + (T.getmonth () +1)/12), (T.getmonth () +1)%12,t.getdate ());
Nmonth = Sdf.format (Nextmonth.gettime ());
} catch (Exception e) {
e.printstacktrace ();
}
return nmonth;
}
4. Solve the next
public static string Getnexthour (string now) {
Date nowdate;
String Nhour=new string ();
SimpleDateFormat sdf=new SimpleDateFormat ("YyyyMMdd HH");
try{
Nowdate=sdf.parse (now);
Long onehour=1000*3600;
Date Nextday=new Date (Nowdate.gettime () +onehour);
Nhour= Sdf.format (Nextday.gettime ());
} catch (Exception e) {
e.printstacktrace ();
}
return nhour;
}