This example for you to share the Java cutting date time code, for your reference, the specific content as follows
/** * @author dy * @since 2016-09-18 & JDK 1.8.0_91 * * public class Datecalculate {static Logger Logger = Logge
Rfactory.getlogger (Datecalculate.class); /** * Cutting time period * * @param datetype transaction type m/d/h/n--> monthly/daily/hourly/per minute * @param start yyyy-mm-dd HH:mm:ss * @para M End YYYY-MM-DD HH:mm:ss * @return/public static list<string> cutdate (String Datetype, string start, St
Ring end) {try {simpledateformat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date Dbegin = Sdf.parse (start);
Date dend = Sdf.parse (end);
Return Finddates (Datetype, Dbegin, dend);
catch (Exception e) {logger.error (E.getmessage (), E);
return null; public static list<string> finddates (String datetype, date dbegin, date dend) throws Exception {list<st
ring> listdate = new arraylist<> ();
Calendar Calbegin = Calendar.getinstance ();
Calbegin.settime (Dbegin); Calendar calend = Calendar.getinsTance ();
Calend.settime (DEnd);
while (Calend.after (calbegin)) {switch (datetype) {case "M": Calbegin.add (Calendar.month, 1);
Break
Case "D": Calbegin.add (Calendar.day_of_year, 1);
Case "H": Calbegin.add (Calendar.hour, 1);
Case "N": Calbegin.add (Calendar.second, 1); } if (Calend.after (Calbegin)) Listdate.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (Calbegin.getti
Me ()));
else Listdate.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (Calend.gettime ());
return listdate;
public static void Main (string[] args) {String start = ' 2016-02-01 00:00:00 ';
String end = "2016-03-02 00:00:00";
list<string> list = cutdate ("D", start, end);
for (String str:list) {System.out.println (str);
}
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.