java 获取上个季度的结束日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10954960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the end date of last quarter
提问by Venkateshwarrao Surabhi
For a given date, how to get the end date of last quarter? I need to run a job, which takes this into account. EDIT: 1st quarter is Jan, Feb, Mar; 2nd is Apr, May, June, so on;
对于给定日期,如何获取上一季度的结束日期?我需要运行一项工作,它考虑到了这一点。编辑:第一季度是一月、二月、三月;2 日是四月、五月、六月,依此类推;
Any help is appreciated. Thanks
任何帮助表示赞赏。谢谢
回答by Roddy of the Frozen Peas
Basically:
基本上:
- Figure out which is the current quarter
- Return the last date of the previous quarter (March 31, June 30, September 30, December 31)
- 找出哪个是当前季度
- 返回上一季度的最后日期(3月31日、6月30日、9月30日、12月31日)
So to figure out which is the current quarter:
int quarter = (myDate.getMonth() / 3) + 1;
(Note that getMonth()is deprecated in favor of Calendar.get(Calendar.MONTH)
.)
因此,要弄清楚哪个是当前季度:(
int quarter = (myDate.getMonth() / 3) + 1;
请注意,不推荐使用getMonth()以支持Calendar.get(Calendar.MONTH)
。)
Then match the previous quarter to a date.
然后将上一季度与日期相匹配。
int prevQuarter = (myDate.getMonth() / 3);
switch(prevQuarter) {
case 3 :
// return September 30
case 2 :
// return June 30
case 1 :
// return March 31
case 0 : default :
// return December 31
}
回答by cjstehno
This is some pretty old code of mine; however, the getQuarter() method will probably do what you need - or at least give you an idea of how to do it.
这是我的一些相当古老的代码;然而, getQuarter() 方法可能会做你需要的 - 或者至少让你知道如何去做。
Hope this helps.
希望这可以帮助。
C
C
回答by Markus Mikkolainen
well quarters only end in months 12,9,6 and 3. all of these have a static length. so there are only 4 valid end dates. compare your month and if it is 1 or 2 or 3, answer is 31.12 of year-1 , if it is 4,5,6 it is 31.3 of this year, if it is 7,8,9 it is 30.6 of this year. if it is 10.11.12 it is 30.9 this year.
井区仅在 12、9、6 和 3 个月结束。所有这些都具有静态长度。所以只有 4 个有效的结束日期。比较你的月份,如果是 1 或 2 或 3,则答案是 year-1 的 31.12,如果是 4,5,6 则是今年的 31.3,如果是 7,8,9 则是今年的 30.6 . 如果是 10.11.12,那么今年是 30.9。
回答by ToastyMallows
http://www.taggercat.com/docs/api/TaggerCat/com/taggercat/util/DateUtils.html#last90Days%28%29
http://www.taggercat.com/docs/api/TaggerCat/com/taggercat/util/DateUtils.html#last90Days%28%29
public static java.util.Date[] last90Days()
Returns the two dates that represent the start and end of the last quarter
返回代表上一季度开始和结束的两个日期
Returns: the two dates that represent this period
返回:代表这个时期的两个日期
This would help, using these dates and the date given, you can determine the date of the last quarter. If I'm understanding your question correctly that is.
这将有助于使用这些日期和给定的日期,您可以确定上一个季度的日期。如果我正确理解你的问题,那就是。