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

如何在java簡單日期格式中添加天數(shù)

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

問題描述

限時送ChatGPT賬號..

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

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

我看過一些關(guān)于它的帖子,但無法讓它發(fā)揮作用,

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,它能夠根據(jù)更改自動滾動日期的各個字段例如單個字段...

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 值,但既然您已經(jīng)這樣做了,我就不打擾了...

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

這篇關(guān)于如何在java簡單日期格式中添加天數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 国产精品明星裸体写真集 | 久久久999精品 | 伊人春色成人网 | 国产日韩精品视频 | 天天艹日日干 | 亚洲高清在线 | 欧美日韩中文字幕在线播放 | 亚洲一区二区在线电影 | 亚洲高清视频在线 | 久久久久久久99 | 在线成人免费视频 | 91视频大全 | 久久精品91久久久久久再现 | 久久另类视频 | 九九综合| 日本午夜免费福利视频 | 亚洲欧美激情精品一区二区 | 免费网站在线 | 精品国产伦一区二区三区观看方式 | 久久伊人精品 | 国产美女在线播放 | 精品av | 国产亚洲精品一区二区三区 | 国产午夜精品久久久 | 在线免费观看毛片 | 久久精品91久久久久久再现 | 天天视频一区二区三区 | 四虎影院新地址 | 成人欧美一区二区三区在线播放 | www.青青草| 欧美日在线 | 精品一区二区三区中文字幕 | 天堂一区二区三区四区 | 婷婷综合激情 | 极情综合网 | 男女视频在线观看网站 | 久久久爽爽爽美女图片 | 亚洲精品国产精品国自产在线 | 亚洲视频在线播放 | 国产欧美一区二区三区另类精品 | 中文字幕 亚洲一区 |