java如何编写年月_如何从Java中的日历对象构建天,月,年的列表?
我強烈建議您避免使用Java中內置的日期和時間API.
相反,請使用Joda Time.該庫類似于(希望如此)將其裝入Java 7的庫,并且比內置API使用起來更令人愉快.
現在,您是否想知道特定月份的天數是一個基本問題?
編輯:這是代碼(帶有示例):
import org.joda.time.*;
import org.joda.time.chrono.*;
public class Test
{
public static void main(String[] args)
{
System.out.println(getDaysInMonth(2009,2));
}
public static int getDaysInMonth(int year,int month)
{
// If you want to use a different calendar system (e.g. Coptic)
// this is the code to change.
Chronology chrono = ISOChronology.getInstance();
DateTimeField dayField = chrono.dayOfMonth();
LocalDate monthDate = new LocalDate(year,month,1);
return dayField.getMaximumValue(monthDate);
}
}
總結
以上是生活随笔為你收集整理的java如何编写年月_如何从Java中的日历对象构建天,月,年的列表?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: unix中的grep家族
- 下一篇: android shape画边框,安卓用