- import java.util.*; //Date
- import java.text.*; //SimpleDateFormat
- public class jva102{
- public static void main(String arg[]){
- //Date d = new Date(); //新產生物件 可指定時間 () 內可帶參數
- // 取得日曆物件裡的實際系統時間
- Date d = Calendar.getInstance().getTime();
- //基本日期格式化
- System.out.println(" 當地時間");
- System.out.println("-------------------------");
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/M/d a hh:mm");
- SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/M/d a hh:mm:ss");
- SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy年M月d日 a hh時mm分ss秒");
- SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy年M月d日 E a hh時mm分ss秒 z");
- System.out.println(sdf1.format(d));
- System.out.println(sdf2.format(d));
- System.out.println(sdf3.format(d));
- System.out.println(sdf4.format(d));
-
- }
- }
複製代碼 |