本文介紹了如何從指定日期獲取上周五的日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我怎樣才能找到上一個(前一個)星期五"的日期或從指定日期開始的任何其他日期?
How can I find out the date of last (previous) "Friday" or any other day from a specified date?
public getDateOnDay(Date date, String dayName) {
// ?
}
推薦答案
我不會給出答案(先自己試試吧!),但是,也許這些提示可以幫助你.
I won't give an answer (try it yourself first!), but, maybe these tips can help you out.
- 您首先需要確定您所在的星期幾.您可能想看看 Java 的 日歷類來了解如何做到這一點.
- 一旦您獲得了您所在的日期,請考慮模數運算符以及如何使用它向后移動以從您當前所在的那一天開始獲取您正在尋找的前一天.(請記住,一周有 7 天,一周中的每一天在這 7 天中占據一個空檔".)
- 一旦確定了兩者之間的天數,您就會想減去.當然,Java框架中也有可以為你加減天數的類……
- You first need to figure out the current day of the week you are on. You may want to take a look at Java's Calendar class to get an idea of how to do that.
- Once you get the date you are on, think about the modulus operator and how you can use that to move backwards to pick up the previous day that you are looking for from the day you are currently at. (Remember, a week is 7 days and each day of the week takes up a "slot" in those 7 days.)
- Once you have the number of days in between, you'll want to subtract. Of course, there are classes that can add and subtract days for you in the Java framework...
我希望這會有所幫助.再次,我鼓勵你總是先自己嘗試這個問題.從長遠來看,您可以通過這種方式學到更多東西,并成為更好的開發(fā)人員.
I hope that helps. Again, I encourage you to always try the problem for yourself, first. You learn far much more that way and be a better developer in the long run for it.
這篇關于如何從指定日期獲取上周五的日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!