Tag:method pack Settings logs mil system minutes time out
Package Com.etc.usual;import Java.util.calendar;import Java.util.date;public class testdate{public static void Main ( String[] args) {//TODO auto-generated method stubdate d1 = new Date (); System.out.println ("D1:" +d1);//d1:thu may 17:03:28 CST 2017//date d2=new Date (115,1,1,1,1,1); Abroad one week time is starting from Sunday//d2.setyear (115); 2015-1900=115//year is starting from 1900. If Setyear here, the year accumulates//d2.setmonth (0); Foreign months starting from 0//system.out.println ("D2:" +d2);//setyear (int year): Years + 1900 represents the current vintage d1.setyear (115); System.out.println ("setyear:" +d1);//setyear:mon may 17:03:28 CST//setmonth (int month): Month value between month-0-11 d1 . setmonth (11); System.out.println ("setmonth:" +d1);//setmonth:fri Dec 17:03:28 CST 2015d1.setmonth (12); If the month exceeds 11, it enters the next year, starting from January of the following year System.out.println ("Setmonth:" +d1);//setmonth:mon Jan 17:03:28 CST 2016d1.setmonth ( -1); If the month is set to a negative number, the current month is subtracted from the set month System.out.println ("setmonth:" +d1);//setmonth:fri Dec 17:03:28 CST 2015system.out.println (); setDate (int date):Date-a day between 1-31 in the month. D1.setdate (1); System.out.println ("SetDate:" +d1);//setdate:tue Dec 17:03:28 CST 2015d1.setdate (31); System.out.println ("SetDate:" +d1);//setdate:thu Dec 17:03:28 CST 2015d1.setdate (32); If the set number of days exceeds the number of days in the current month, enter the first day of the next January and start the chronograph System.out.println ("SetDate:" +d1);//setdate:fri Jan 17:03:28 CST 2016d1.setdate (-2); If the number of days is set to negative, the current number of days is automatically reduced by the number of days set to start the chronograph System.out.println ("SetDate:" +d1);//setdate:tue Dec 17:03:28 CST 2015system.out.println (); The range of sethours (int hours) hours 0~23d1.sethours (20); System.out.println ("sethours:" +d1);//sethours:tue Dec 20:03:28 CST 2015d1.sethours (23); System.out.println ("sethours:" +d1);//sethours:tue Dec 23:03:28 CST 2015d1.sethours (24); The hour exceeds 23, then enters the next day System.out.println ("sethours:" +d1);//sethours:wed Dec 00:03:28 CST 2015d1.sethours (-1); The number of hours is negative, then enter the hour of the previous day System.out.println ("sethours:" +d1);//sethours:tue Dec 23:03:28 CST 2015system.out.println (); setminutes (int minutes) d1.setminutes (55); System.out.println ("Setminutes: "+d1");//setminutes:tue Dec 23:55:28 CST 2015d1.setminutes (60);//min value exceeds 59, hour plus one System.out.println ("Setminutes:" +d1 );//setminutes:wed Dec 00:00:28 CST 2015d1.setminutes (-5);//minute value is negative, hour minus one, and minutes value is automatically subtracted from 60 for the set minute value System.out.println (" Setminutes: "+d1");//setminutes:tue Dec 23:55:28 CST 2015system.out.println (); setseconds (int seconds) d1.setseconds (55); System.out.println ("setseconds:" +d1);//setseconds:tue Dec 23:55:55 CST 2015d1.setseconds (60); System.out.println ("setseconds:" +d1);//setseconds:tue Dec 23:56:00 CST 2015d1.setseconds (-1); System.out.println ("setseconds:" +d1);//setseconds:tue Dec 23:55:59 CST 2015system.out.println (); ToString () System.out.println ("ToString:" +d1.tostring ())//tostring:tue Dec 23:55:59 CST 2015//after (Date when) measured Test whether this date is after the specified date. Date D2=new date ();//Current time D1:tue Dec 23:55:59 CST 2015system.out.println ("D1.after (D2):" +d1.after (D2));//d1.after (d 2): False//before (date when) tests whether this date is before the specified date. System.out.println ("D1.before (D2):" +d1.before (D2));//D1.before (D2): True//compareto (date anotherdate)//If the parameter date equals this date, the value 0 is returned, and if this date precedes the date parameter, a value less than 0 is returned; After the Date parameter, a value greater than 0 is returned. System.out.println ("CompareTo:" +d1.compareto (D2)); Compareto:-1//equals (Object obj)//compares the equality of two dates. The result is true when and only if the argument is not null and is a Date object that represents the same point in time (to milliseconds) as this object. Date D3=new date ();D ate d4=new date (); System.out.println (d3+ "---" +d4)//thu may 17:03:28 CST---Thu CST 17:03:28 ("Equals: "+d3.equals (D4));//equals:true//calculate the number of milliseconds for the Calendar c=calendar.getinstance (); C.settime (D3); System.out.println (C.gettimeinmillis ());//1493888608957c.settime (D4); System.out.println (C.gettimeinmillis ());//1493888608957}}
Java.util.Date