Method of Java date time operation
This example shares the basic operation methods of Java date and time for your reference. The specific contents are as follows
1. Obtain the calendar instance: calendar c = calendar getInstance(); 2. Define the format of date / time: simpledateformat SDF = new simpledateformat ("yyyy MM DD HH: mm: SS"); 3. Convert the date / time to a fixed format and use the format () method of simpledateformat: String datetime = SDF format(c.getTime()); 4. Convert the string to date / time, and use the parse() method of simpledateformat: Date d = sdf3 parse("2016-08-08 16:43:00"); 5. For the increase and decrease of date / time, use the add () method of calendar, such as reducing the date by 100 days: c.add (calendar. Date, - 100); 6. For setting the date / time, use the set() method of calendar. For example, when the hour is set to 0: c.set (calendar. Hour_of_day, 0); example:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.