1、編寫java代碼
以下是java代碼
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; //輸入一個數,毫秒轉化為當前時間 public class MSMain { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("請輸入毫秒數(溫馨提示,輸入-1退出):"); Long mSeconds = sc.nextLong(); if(mSeconds == -1L) { System.out.println("您已成功退出,再見"); break; } System.out.println("對應的時間是(12小時制):" + transferLongToDate("yyyy年MM月dd日 hh:mm:ss", mSeconds)); System.out.println("對應的時間是(24小時制):" + transferLongToDate("yyyy年MM月dd日 kk:mm:ss", mSeconds)); } } private static String transferLongToDate(String dateFormat, Long millSecond) { Date time = new Date(millSecond); SimpleDateFormat formats = new SimpleDateFormat(dateFormat); return formats.format(time); } }
將文件用記事本打開,另存為MSMain.java文件,編碼選擇ANSI
2、設置環境變量
CLASSPATH值為. 代表在當前目錄下尋找class文件
3、運行腳本
shift+鼠標右鍵,cmd進入當前目錄
運行
javac MSMain.java #生成class文件
java MSMain #運行class文件