「java日期季度」java 日期 周几

博主:adminadmin 2022-12-16 05:57:09 71

本篇文章给大家谈谈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 + "";

}

// 设置完成

用java怎么计算两个日期之间年数,季度数,月数

应该可以满足你的需求了 /** * * 计算两个日期相差的月份数 * * @param date1 日期1 * @param date2 日期2 * @param pattern 日期1和日期2的日期格式 * @return 相差的月份数 * @throws ParseException

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!");  } }

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

}

}

java日期季度的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 日期 周几、java日期季度的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-16,除非注明,否则均为首码项目网原创文章,转载请注明出处。