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

下個(gè)月的第一天使用 java Joda-Time

First day of next month with java Joda-Time(下個(gè)月的第一天使用 java Joda-Time)
本文介紹了下個(gè)月的第一天使用 java Joda-Time的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

你會(huì)如何用 org.joda.time 包重寫下面的方法,它返回下個(gè)月的第一天/joda-time/" rel="noreferrer">Joda-Time?

How would you rewrite the method below, which returns the first day of next month, with the org.joda.time package in Joda-Time?

public static Date firstDayOfNextMonth() {
    Calendar nowCal = Calendar.getInstance();
    int month = nowCal.get(Calendar.MONTH) + 1;
    int year = nowCal.get(Calendar.YEAR);

    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Date dueDate = new Date(cal.getTimeInMillis());

    return dueDate;
}

推薦答案

   LocalDate today = new LocalDate();
   LocalDate d1 = today.plusMonths(1).withDayOfMonth(1);

更容易和更清潔,不是嗎?:-)

A little easier and cleaner, isn't it? :-)

更新:如果你想返回一個(gè)日期:

Update: If you want to return a date:

return new Date(d1.toDateTimeAtStartOfDay().getMillis());

但我強(qiáng)烈建議您避免將純 DATE 類型(即日歷中的一天,沒有時(shí)間信息)與 DATETIME 類型混合,特別是與可怕的 java.util.Date 一樣的物理"日期時(shí)間類型 .這有點(diǎn)像從整數(shù)和浮點(diǎn)類型轉(zhuǎn)換,你必須小心.

but I strongly advise you to avoid mixing pure DATE types (i.e. a day in the calendar, without time information) with DATETIME types, specially with a "physical" datetime type as is the hideous java.util.Date . It's somewhat like converting from-to integer and floating types, you must be careful.

這篇關(guān)于下個(gè)月的第一天使用 java Joda-Time的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 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)前星期幾的值)
主站蜘蛛池模板: 午夜精品国产精品大乳美女 | 91视频亚洲 | 精品视频久久 | 亚洲一区二区国产精品 | 久久精品亚洲 | 视频一二区 | 成人免费视屏 | 亚洲乱码在线观看 | 国产日韩久久 | 亚洲成人精品视频 | 深夜福利av | 日韩城人网站 | 成人福利网站 | a视频在线观看 | 欧美不卡一区二区三区 | 黄色大片在线播放 | 欧美亚洲在线观看 | 在线a | 在线观看一区 | 日日干日日操 | 久久大 | 中文字幕不卡在线观看 | 夜夜操av | 日韩视频在线免费观看 | 久久精品一二三 | 久久亚洲精品视频 | 女人av在线 | 欧美黄色一级大片 | 综合色av | 色婷婷网 | 久久免费看视频 | 成人羞羞国产免费游戏 | 国产一区精品在线观看 | 天天爱天天色 | 国产二区精品 | 日韩精品免费 | 青青久久久 | 六月激情| 特黄aaaaaaaaa真人毛片 | 99热视| 乳色吐息在线观看 |