1. How to calculate the interval between two time?
Interval = Date1.gettime () - DATE2.GETTIME (); gets the number of milliseconds.
Except 1000 is second, then in addition to 60 is division, then 60 is hours ..............................
Remember that all time classes in the Java standard library are transformed by this, but he wrote some
The transformation method is given to you. But you are inseparable from this millisecond.
2. T = calendar.getInstance (); m = t.Get (t.month) 1; why do you add one?
In Java language, the value of DATE's Month is: 0 to 11, and the natural expression of people is different from people.
3. The difference between the system time and the current date?
The system time is exact, it should be
System.currentTimeMillis ();
New date () is the current date, although it getTime (); and system.currenttimemillis ();
Same, but system.currenttimemillis ();
4. How do I calculate the difference between the two days?
Long Begintime = Begindate.getTime ();
Long endtime2 = enddate.gettime ();
Long BetWeendAys = (long) / (1000 * 60 * 60 * 24) 0.5);
5. How to compare the date of date?
the first method:
Use Calendar Object to Compare
Java.util.calendar class can be used to compare date. in Order to do this,
You Guy Should Parse That String Into Int Year, Month, Day and Construction A
Calendar Object, And the Do Comparison.
BELOW Is A Sample
StringTokenizer token = New StringTokenizer (Your string, "-");
INT year = integer.parseint (token.nextToken ());
Int month = integer.parseint (token.nextToken ());
INT day = integer.parseint (token.nextToken ());
Calendar Date = Calendar.getInstance ();
Date.set (Year, Month, Day);
Calendar Today = Calendar.getInstacne ();
IF (Date.After (Today)) {
// ......
}
The second method
Date nowDate = new date (); // Current time r
Long NowTime = nowDate.gettime;
Long lasttime = utertime.longvalue (); // previous time R
Long Time = NOWTIME-LastTime; // Time Separation Comparison Comparison.
IF (TIME> (long) 60000) // 1 minute {}
In addition, the following reference can be used
Use timestamps, Date.getTime () can change the current time to timestamp,
Use compareto ();
Use Before (), After (), Equals ();
6. Question Reated Date
purpose:
First date
Java.text.SIMPLEDATEFORMAT FORMATTER = New Java.text.SIMPLEDATEFORMAT ("YYYY-MM-DD"); string riqi = formatter.format (currenttime_1);
Second time R
Java.text.dateFormat Format1 = new java.text.SIMPLEDATEFORMAT ("hhmmss");
Java.util.date currenttime_2 = new java.util.date ();
String Shijian = Format1.Format (CurrentTime_2);
The result is the result is
2002-02-19 and 115324 (11:53:20 24 seconds)
achieve:
Java.text.SIMPLEDATEFORMAT formatter = new java.text.SIMPLEDATEFORMAT ("YYYY-MM-DD-H-MM-SS");
Java.util.date currenttime_1 = new java.util.date ();
String str_date = formatter.format (currentTime_1);
StringTokenizer token = New StringTokenizer (Str_Date, "-");
String year = token.nextToken ();
String Month = token.nextToken ();
String day = token.nextToken ();
String hh = token.nextToken ();
String mm = token.nextToken ();
String ss = token.nextToken ();
String riqi = year "year" month "month" " " " " "point" mm "points" SS "second";
String newdir = year month day;
String wenjian = HH mm ss;
7. How do you get a month?
Java.util.calendar Date = java.util.calendar.GetInstance ();
System.out.println (Date.Day_Of_Month);