Home > Back-end >  Which bosses know through the appropriate method to compare the Date class 1486448690841 millisecond
Which bosses know through the appropriate method to compare the Date class 1486448690841 millisecond

Time:10-13

How do you write the code for bosses simply thank thank

CodePudding user response:

Public static void main (String [] args) {
System. The out. Println (" DateUtils. Main: "+ new Date (). The getTime ());
String yourTimeString="1486448690841";
Long yourTime=Long. ParseLong (yourTimeString);
Long theTime=new Date (). GetTime ();
TheTime.com pareTo (yourTime);
System. The out. Println (" comparative size "+ theTime.com pareTo (yourTime));
}
According to the compareTo () method returns a value judgment is greater than zero is equal to 1 is less than 1
You write a few main method to run, to know

CodePudding user response:

Date has getTime () method can transform time in milliseconds

CodePudding user response:

Public static void main (String [] args) {
Long time=1486448690841 l;
//a
//create a new date class
Date date=new Date();
//the default to the current time
System. The out. Println (" the current time is: "+ date);
//set the number of milliseconds for you
The date. The setTime (time);
System. The out. Println (" I set the time: "+ date);
//before judge two time
System. The out. Println (date. Before (new date ()));

//way.
//get the current time the number of milliseconds
long l=System.currentTimeMillis();
//directly compare two milliseconds, the smaller of the time of the earlier
System. Out.println (time & lt; L);
}

CodePudding user response:

Convert LocalDateTime, punctuated with isAfter, methods of isBefore,
  • Related