日历操作

                    日历操作

获得年月日

 

代码
/**
* @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");
}
}

 

 

posted @ 2010-12-19 22:09  meng72ndsc  阅读(190)  评论(0编辑  收藏  举报