重新出發 Java基礎 常用的時間API23

2021-09-12 04:06:50 字數 636 閱讀 5243

構造方法

date():建立當前系統時間的date物件

date(long    date):根據「指定時間」建立date物件

date常用

毫秒------>date

date------>毫秒     long    gettime();

******dateformat    sdf  =  new ******dateformat(「yyyy年mm月dd日」);

date    date    =    new    date();

string    s   =   sdf.format(date);

date    d  =  sdf.parse(「2023年08月26日」);

calendar:日曆,提供了一些操作年月日的方法

calendar    c = calendar.getinstance();

int    year    =    c.get(calendar.year);

int    month  =  c.get(calendar.month);

int    day =  c.get(calendar.day_of_month);

c.set(calendarm,day_of_month,20);

重新出發 Java基礎 異常29

跟類throwable 最頂類 error 不能處理的問題 exception 可以處理的問題 jvm處理異常方式 出現異常沒處理 jvm會幫我們進行處理,原因和位置顯示在命令列 終止程式 異常處理方式 自己處理還能繼續進行 捕獲異常 trycatch 異常物件 throw new exceptio...

java常用 日期時間格式的轉化,以及時間的計算

dateformat format new dateformat yyyy mm dd hh mm ss sss date date null try catch parseexception e return date 2.日期格式轉換為字串 dateformat format new datef...

Java中獲取當前時間的常用方法

方法1 mm要大寫,ss要小寫,dd大寫表示一年中的第幾天,dd小寫表示一月中的第幾天 大寫hh和小寫hh表示24小時制和12小時制 date date new date 格式化日期 dateformat sdf new dateformat yyyy mm dd hh mm ss system.o...