java milliseconds into the current time

1, write java code

The following is a java code

the java.text.SimpleDateFormat Import; 
Import java.util.Date; 
Import java.util.Scanner; 

// input a number of milliseconds into the current time 
public  class MSMain { 

    public  static  void main (String [] args) { 
        Scanner SC = new new Scanner (the System. in );
         the while ( to true ) { 
            the System. OUT .println ( " Please enter the number (tips, enter the exit -1) ms: " ); 
            Long mseconds = sc.nextLong (); 
            
            IF (= mseconds = - 1L ) { 
                the System.OUT .println ( " You have successfully quit, bye " );
                 BREAK ; 
            } 
            
            System. OUT .println ( " corresponding to the time (12-hour): " + transferLongToDate ( " yyyy Year MM Month dd Day hh: mm: ss " , mseconds)); 
            the system. OUT .println ( " corresponding to the time (24 hour): " + transferLongToDate ( " YYYY, mM-dd day KK: mm: SS " , mseconds)); 
        } 
    } 
    
    Private  static  String transferLongToDate (String dateFormat, Long millSecond) {
        a date Time = new new a Date (millSecond);
        SimpleDateFormat formats = new SimpleDateFormat(dateFormat);
        return formats.format(time);
    }
}

The files are opened using Notepad, save, file encoding selection of ANSI MSMain.java

2, set the environment variable

CLASSPATH is representative looking for class files in the current directory

 

 

 

3, run the script

shift + right mouse button, cmd into the current directory

run

javac MSMain.java # generated class file 
java MSMain # run the class file

 

 

Guess you like

Origin www.cnblogs.com/longchengruoxi/p/11669971.html