Calendar類怎么在java項目中使用?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
java中的Calendar在開發(fā)中經常被忽略,這篇博客總結一下這個類,對后面項目中使用時期的時候有幫助。
Calendar常量(field)的作用
Calendar cal = Calendar.getInstance(); cal.get(Calendar.DATE);//-----------------------當天 1-31 cal.get(Calendar.DAY_OF_MONTH);//---------------當天 1-31 cal.get(Calendar.DAY_OF_WEEK);//----------------從星期天開始計算,如果今天星期二,那么返回3 cal.get(Calendar.DAY_OF_YEAR);//---------------- cal.get(Calendar.HOUR);//-----------------------12小時制 cal.get(Calendar.HOUR_OF_DAY);//----------------24小時制,一般使用這個屬性賦值 cal.get(Calendar.MILLISECOND);//---------------- cal.get(Calendar.MINUTE);//--------------------- cal.get(Calendar.SECOND);//--------------------- cal.get(Calendar.WEEK_OF_MONTH);//-------------- cal.get(Calendar.WEEK_OF_YEAR);//--------------- cal.get(Calendar.MONTH);//-----------------------月份獲取需要 +1,那么,賦值時需要 -1