本文介紹了Java 日歷日期錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
誰能幫我理解為什么我得到不同的月份值
Can anyone please help me understand why I am getting different month values for
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.format(cal.getTime())
+ "--"
+ cal.get(Calendar.MONTH));
令人驚訝的顯示
09/09/2012--8
推薦答案
在 Calendar
類,MONTH
從索引 0
開始.因此,January
為 0,February
為 1,因此 September
為 8.
In Calendar
class, MONTH
start from index 0
. So, January
is 0, February
is 1, and hence September
is 8.
PS:-確實這是Calendar
類中的Inconsistency
,所以我建議你看看Joda-Time API
打造您的生活處理日期時間數(shù)據(jù)時更容易.
P.S.: - That's true that this is an Inconsistency
in Calendar
class, so I would suggest you to take a look at Joda-Time API
to make your life easier while working with date-time data.
這篇關于Java 日歷日期錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!