久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 Java 中的日歷對象構(gòu)建天、月、年的列表

How can I build a list of days, months, years from a calendar object in Java?(如何從 Java 中的日歷對象構(gòu)建天、月、年的列表?)
本文介紹了如何從 Java 中的日歷對象構(gòu)建天、月、年的列表?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我想為一個表單構(gòu)建一個日期小部件,它有一個包含月、日、年的選擇列表.由于列表根據(jù)月份和年份而有所不同,因此我無法將其硬編碼為 31 天.(例如 2 月有 28 天而不是 30 或 31 天,有些年份甚至是 29 天)如何使用日歷或 joda 對象為我構(gòu)建這些列表.

I want to build a date widget for a form, which has a select list of months, days, years. since the list is different based on the month and year, i cant hard code it to 31 days. (e.g february has 28 days not 30 or 31 and some years even 29 days) How can I use the calendar or joda object to build me these lists.

推薦答案

強烈建議您避免使用 Java 中內(nèi)置的日期和時間 API.

I strongly recommend that you avoid the built-in date and time APIs in Java.

改為使用 Joda Time.這個庫類似于(希望如此!)進(jìn)入 Java 7 的庫,并且比內(nèi)置 API 更易于使用.

Instead, use Joda Time. This library is similar to the one which will (hopefully!) make it into Java 7, and is much more pleasant to use than the built-in API.

現(xiàn)在,您想知道特定月份的天數(shù)是基本問題嗎?

Now, is the basic problem that you want to know the number of days in a particular month?

這是代碼(帶有示例):

Here's the code (with a sample):

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);
    }
}

這篇關(guān)于如何從 Java 中的日歷對象構(gòu)建天、月、年的列表?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 日韩三级一区 | 五月天天丁香婷婷在线中 | 欧美成人精品欧美一级 | 精品久久久久久久久久久久久 | 色av一区二区三区 | 国产成人小视频 | 久久精品国产99国产精品 | 国产成在线观看免费视频 | japanhd美女动 | 一级毛片网 | 久久久久一区二区三区 | 国产一区高清 | 久久国产电影 | 日本国产一区二区 | 一区天堂 | 亚洲日日 | 日本不卡在线视频 | 亚洲一区在线播放 | 情侣av | 深夜福利影院 | 欧美亚洲国产日韩 | 亚洲入口| 麻豆久久久久久 | 国产高清一区二区三区 | 欧美日韩国产在线观看 | 日韩在线免费 | 一级黄色淫片 | 精品国产乱码久久久久久闺蜜 | 在线国产一区二区 | 国产高清视频在线 | 日本不卡免费新一二三区 | 国产精品a一区二区三区网址 | 91传媒在线观看 | 中文字幕亚洲国产 | 国产aa | 精品亚洲永久免费精品 | 亚洲欧美一区二区三区在线 | 高清黄色网址 | 成人久久久| av免费入口 | 日韩欧美在线观看视频网站 |