/*
* 如何获取系统当前日期
*/
public static String getNowTime(){
Calendar ca = Calendar.getInstance();
int year = ca.get(Calendar.YEAR);//获取年份
int month=ca.get(Calendar.MONTH);//获取月份
int day=ca.get(Calendar.DATE);//获取日
String riqi = String.valueOf(year+"-"+month+"-"+day);
int minute=ca.get(Calendar.MINUTE);//分
int hour=ca.get(Calendar.HOUR);//小时
int second=ca.get(Calendar.SECOND);//秒
String time = String.valueOf(hour+"-"+minute+"-"+second);
int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK);
String weekDay = "星期"+String.valueOf(WeekOfYear);
return riqi+" " + time + " " + weekDay ;
}
/**
* 获得指定日期的前一天
* @param specifiedDay
* @return
* @throws Exception
*/
public static String getSpecifiedDayBefore(String specifiedDay){
Calendar c = Calendar.getInstance();
Date date=null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day=c.get(Calendar.DATE);
c.set(Calendar.DATE,day-1);
String dayBefore=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return dayBefore;
}
/**
* 获得指定日期的后一天
* @param specifiedDay
* @return
*/
public static String getSpecifiedDayAfter(String specifiedDay){
Calendar c = Calendar.getInstance();
Date date=null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day=c.get(Calendar.DATE);
c.set(Calendar.DATE,day+1);
String dayAfter=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return dayAfter;
}
/*
* 如何获取指定日期的前一天是周几
*/
public static String getBefforeWeekday(String specifiedDay){
String []ss = specifiedDay.split("-");
int y=Integer.parseInt(ss[0]);
int m=Integer.parseInt(ss[1]);
int d=Integer.parseInt(ss[2]);
int n=d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1;
String weekDay = null ;
switch((n-1)%7){
case 1:weekDay = "星期一";
break;
case 2:weekDay = "星期二";
break;
case 3:weekDay = "星期三";
break;
case 4:weekDay = "星期四";
break;
case 5:weekDay = "星期五";
break;
case 6:weekDay = "星期六";
break;
case 7:weekDay = "星期天";
}
return weekDay;
}
/*
* 如何获取指定日期的下一天是周几
*/
public static String getAffterBefforeWeekday(String specifiedDay){
String []ss = specifiedDay.split("-");
int y=Integer.parseInt(ss[0]);
int m=Integer.parseInt(ss[1]);
int d=Integer.parseInt(ss[2]);
int n=d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1;
String weekDay = null ;
switch((n+1)%7){
case 1:weekDay = "星期一";
break;
case 2:weekDay = "星期二";
break;
case 3:weekDay = "星期三";
break;
case 4:weekDay = "星期四";
break;
case 5:weekDay = "星期五";
break;
case 6:weekDay = "星期六";
break;
case 7:weekDay = "星期天";
}
return weekDay;
}