日历操作

获得年月日

 

代码
/**
* @description 该方法用于得到年月日
*
@return 按照"20101210"的形式返回年月日字符串
*/
public static String getYearMonthDay() {
Calendar calendar
= Calendar.getInstance();
String year
= calendar.get(Calendar.YEAR) + "";
String month
= calendar.get(Calendar.MONTH) + 1 + "";
String day
= calendar.get(Calendar.DAY_OF_MONTH) + "";

month
= month.length() == 1 ? "0" + month : month;
day
= day.length() == 1 ? "0" + day : day;
return year + month + day;
}

 

 

获得时分秒

 

代码
/**
* @description 该方法用于得到时分秒
*
@return 按照"212436"的形式返回时分秒字符串
*/
public static String getHourMinuteSecond() {
SimpleDateFormat sdf
= new SimpleDateFormat("HHmmss");
String time
= sdf.format(new Date());
return time;
}

 

 

 

判断是否是闰年?

 

代码
public static void runnian()
{
boolean isRunNian = new GregorianCalendar().isLeapYear(2010);// 判断是否是闰年
if(isRunNian)
{
System.out.println(
"toyear is leap year");
}
else
{
System.out.println(
"toyear is non-leap year");
}
}

 

 

相关文章:

  • 2021-06-25
  • 2022-12-23
  • 2021-12-09
  • 2021-04-15
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-03
  • 2022-12-23
  • 2022-01-14
  • 2021-08-15
  • 2021-04-21
  • 2021-10-28
相关资源
相似解决方案