Java如何 根据指定的时间段获取时间段内的所有年、季度、月、周。

Python015

Java如何 根据指定的时间段获取时间段内的所有年、季度、月、周。,第1张

你的意思是给一个时间跨度好比

2010/3/2-2015/05/06

然后输出 2010 2011 2012 2013 2014 2015 其他类似,是这个意思吗?

String format=new Format("yyyy"),format(new Data())

这样可以获得数字类型的年

Integer int =Integer.parsreInteger(format)

这样可以获得整形的年

之后就是进行循环读取即可。

这个是我随便写的,其中没有对输入月份进行限制!

import java.util.*

public class yuefen {

public static void main(String [] args)

{

String str="这个月份是"

Scanner s= new Scanner(System.in)

int temp=s.nextInt()

switch(temp)

{

case 1:

case 2:

case 3:

str+="spring"

break

case 4:

case 5:

case 6:

str+="autumn"

break

case 7:

case 8:

case 9:

str+="summer"

break

case 10:

case 11:

case 12:

str+="winter"

break

}

System.out.println(str)

}

}

这个需要取么,都是定死的,每年都一样

第一季度:1月1号,3月31号

第二季度:4月1号,6月30号

第三季度:7月1号,9月30号

第四季度:10月1号,12月31号

和闰年也没关系,不需要编程计算,最多定义常量来保存