
正文
java代码获取季度,java 获取季度
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java代码实现根据传入的日期,返回传入日期的所在季度(传入:2014/2/1,返回2014年1季度)
// 获得月份month
String month = "09";
// 设置季度
String jd = null;
if(Integer.parseInt(month) %3 == 0){
jd = Integer.parseInt(month)/3 + "";
} else {
jd = Integer.parseInt(month)/3 + 1 + "";
}
// 设置完成
相关问答
Q1: 用java怎么取某年某个季度的开始日期与结束日期?
这个需要取么,都是定死的,每年都一样
第一季度:1月1号,3月31号
第二季度:4月1号,6月30号
第三季度:7月1号,9月30号
第四季度:10月1号,12月31号
和闰年也没关系,不需要编程计算,最多定义常量来保存
Q2: java编程,输入月份判断季节
代码喝注释如下:
public static void main(String[] args) { System.out.print("Please input the month to check:"); int month = new Scanner(System.in).nextInt();//月份//月份不在1~12的情况,提醒输入错误 if (month = 0 || month 12) { System.out.println("Error! month must be between 1 and 12!"); }
//1-3月是春天
else if (month = 3) { System.out.println("Month " + month + " is in Spring!"); }
//4-6月是夏天
else if (month = 6) { System.out.println("Month " + month + " is in Summer!"); }
//7-9月是秋天
else if (month = 9) { System.out.println("Month " + month + " is in Autumn!"); }
//10-12月是冬天
else { System.out.println("Month " + month + " is in Winter!"); } }
Q3: java编写程序求出月份对应的季度名称?
这个是我随便写的,其中没有对输入月份进行限制!
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);
}
}
Q4: Java如何 根据指定的时间段获取时间段内的所有年、季度、月、周。
你的意思是给一个时间跨度好比
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);
这样可以获得整形的年
之后就是进行循环读取即可。








