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

如何在java簡單日期格式中添加天數

how to add days to java simple date format(如何在java簡單日期格式中添加天數)
本文介紹了如何在java簡單日期格式中添加天數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我應該如何將 120 天添加到我使用簡單日期格式獲得的當前日期?

How should I add 120 days to my current date which I got using simple date format?

我看過一些關于它的帖子,但無法讓它發揮作用,

I have seen few posts about it but couldn't get it to work,

我的代碼如下:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
//get current date time with Date()
Date date = new Date();

我需要使用 Calendar 庫還是只使用簡單的日期格式?

Do I need to use the Calendar library or can I just do it with simple date format?

推薦答案

基本上,您可以簡單地使用 Calendar,它能夠根據更改自動滾動日期的各個字段例如單個字段...

Basically, you can simple use a Calendar which has the capacity to automatically roll the various fields of a date based on the changes to a single field, for example...

Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 120);
date = cal.getTime();

仔細查看 日歷 了解更多詳情.

Take a closer look at Calendar for more details.

是的,有一種使用 Joda Time 的方法,但我可以更快地輸入這個示例;)

Yes, there is a way to do this using Joda Time, but I could type this example quicker ;)

更新 JodaTime 示例

以下是使用 JodaTime 的示例.您可以直接使用 JodaTime 解析 String 值,但既然您已經這樣做了,我就不打擾了...

The following is an example using JodaTime. You could parse the String value directly using JodaTime, but since you've already done that, I've not bothered...

Date date = ...;
DateTime dt = new DateTime(date);
dt = dt.plusDays(120);
date = dt.toDate();

這篇關于如何在java簡單日期格式中添加天數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
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 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 福利小视频 | 国产精品视频一区二区三区 | 99久久久 | 免费的黄色大片 | 黄色小视频在线免费观看 | 国产成人在线观看免费网站 | 国产精品自拍小视频 | 成人精品在线观看 | 精品免费视频 | 可以免费看黄色的网站 | 私库av在线 | 免费视频a| h片在线观看免费 | 在线观看国产一区二区 | 亚洲一区中文字幕 | 日韩小视频在线观看 | 天天插天天干 | 五月婷在线 | 四虎影视大全 | 日韩不卡一区 | 午夜激情在线观看 | 成人一级毛片 | 欧美一级色 | 69er小视频| 精品国产99 | 五月天毛片 | 国产精品第一区 | 窝窝午夜精品一区二区 | 国产第一av | 久久精品99久久久久久 | 日韩国产一区二区三区 | 伊人91 | 国语av| 久久久久久黄色 | 天天久久| 日韩在线综合 | 日韩精品久久久久久久 | 黄色小视频免费观看 | 午夜一级视频 | 亚洲一区二区在线播放 | 久久精品国产一区 |