Java program modules usually have their own public date-time processing classes, mainly implemented such as:
Time format, get the current date before and after a time, date time comparison and other functions;
1. Date formatting
Date date = new Date ();
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String StartDate = Format.format (date); Get the formatted string
2. Date increase or decrease
Date date = new Date ();
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Calendar C = calendar.getinstance ();
C.settime (date);
C.add (Calendar.day_of_year, 7); The current time back 7 days, if you want to use 7 days before the current time-7
Format.format (C.gettime ())
3. Some other uses
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyymmddhhmmss", Locale.simplified_chinese); Add local time zone settings
4. It is often necessary to add a date-time processing public class to handle
Like what:
/**
* Get the number of seconds from 1970-1994
* @param date Time
* @return Count value
*/
public static long getsecondfrom70to94 ()
{
Calendar cs = Calendar.getinstance ();
Cs.set (Calendar.year, 1970);
Cs.set (calendar.month, 1);
Cs.set (calendar.day_of_month, 1);
cs.set (calendar.hour_of_day, 0);
cs.set (calendar.minute, 0);
cs.set (calendar.second, 0);
cs.set (calendar.millisecond, 0);
Calendar CE = calendar.getinstance ();
Ce.set (Calendar.year, 1994);
Ce.set (Calendar.month, 1);
Ce.set (Calendar.day_of_month, 1);
Ce.set (calendar.hour_of_day, 0);
Ce.set (calendar.minute, 0);
Ce.set (Calendar.second, 0);
Ce.set (Calendar.millisecond, 0);
Return (long) (Ce.gettimeinmillis ()-Cs.gettimeinmillis ());
}
Summary of Java time and date processing