The first two classes to introduce to you are SimpleDateFormat and calendar
A: SimpleDateFormat dateformat=new simpledateformat ("yyyy-mm-dd hh:mm:ss")/
There is also a new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Loc ale.uk)//The output looks like Wed Mar 00:00:00 CST 2018
The parameter is the format of the date you need to format, this is important, remember the month is the uppercase mm, if you write in lowercase, the class will think of it as you want to take the time
Minutes, of course, means that the minutes can not be written in uppercase.
This class provides two relatively important methods:
1.dateformat.format (date);
This date is the format of the time, formatted with a string, the form of the string is of course the format of the argument of this class.
2.dateformat.parse (datestring);
The entry parameter is a string representing the time, returning an object of a time type.
Second: Calendar class: Mainly used to deal with time, add and subtract, get a variety of time
Calendar calendar=calendar.getintance ();
Calendar.settime (date);//date is a date format that puts the time you need to process it in.
(1) The increase and decrease of the date < year, month and day >
Calendar.add (calendar. year,-3);
First, the location of the red is to indicate that you want to add and subtract the part of your date, the date of the addition and subtraction of the benchmark is not the same, they can be the following is my situation:
Year to years plus minus
Date to day plus minus
Hour_of_day hours plus minus
Day_of_week_in_month to the week of the month. For example: 2018-02-27 and then minus one is 2018-02-20.
There is also the Calendar.get (temp) method, which is used to obtain information from a specific date
For example: Temp=calendar. Day_of_week //Days of the week, note that Saturday is the first day of the week
Temp=calendar. Week_of_month //Get this date is the first few weeks of this month.
Temp=calendar. Date//Get this day is the day of the month
Operations on dates in Java, Comparison of dates, plus and minus