//得到传入时间周一的时间
public String getMonday(String Monday){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Monday); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance(); //初始化日历,为今天
c.setTime(d); //设置日历为上面的Date日期
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(c.getTime());
}
//得到传入时间周末的时间
public String getWeekend(String Weekend){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Weekend); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 7);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(c.getTime());
}
//得到传入时间几年前的时间
public String getYear(String Year){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Year); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.add(Calendar.YEAR, -1);//得到前5年
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime=formatter.format(c.getTime());
return mDateTime;
}
/**
* 得到本月的第一天
* @return
*/
public String getMonthFirstDay(String time) {
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(time); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.set( Calendar.DATE, 1 );
SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd");
String s=simpleFormate.format(c.getTime());
return s;
}
/**
* 得到本月的最后一天
*
* @return
*/
public String getMonthLastDay(String time) {
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(time); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.set( Calendar.DATE, 1 );
c.roll(Calendar.DATE, - 1 );
SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd");
String s=simpleFormate.format(c.getTime());
return s;
}
public String getMonday(String Monday){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Monday); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance(); //初始化日历,为今天
c.setTime(d); //设置日历为上面的Date日期
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(c.getTime());
}
//得到传入时间周末的时间
public String getWeekend(String Weekend){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Weekend); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 7);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(c.getTime());
}
//得到传入时间几年前的时间
public String getYear(String Year){
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(Year); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.add(Calendar.YEAR, -1);//得到前5年
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime=formatter.format(c.getTime());
return mDateTime;
}
/**
* 得到本月的第一天
* @return
*/
public String getMonthFirstDay(String time) {
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(time); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.set( Calendar.DATE, 1 );
SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd");
String s=simpleFormate.format(c.getTime());
return s;
}
/**
* 得到本月的最后一天
*
* @return
*/
public String getMonthLastDay(String time) {
Date d=null;
try{
d=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(time); //把字符串转换为Date
}catch(Exception e){}
Calendar c = Calendar.getInstance();
c.setTime(d); //设置日历为上面的Date日期
c.set( Calendar.DATE, 1 );
c.roll(Calendar.DATE, - 1 );
SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd");
String s=simpleFormate.format(c.getTime());
return s;
}