码迷,mamicode.com
首页 > 编程语言 > 详细

Java--以周作为时间变化

时间:2016-05-18 12:38:41      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

 一、获取本周

 weekFirst_date=new Date();
  weekLast_date=new Date();
  weekFirst_calendar=Calendar.getInstance();
  weekLast_calendar=Calendar.getInstance();
  weekFirst_time=null;
  weekLast_time=null;
  
  weekFirst_calendar.setFirstDayOfWeek(Calendar.MONDAY);
  weekFirst_calendar.add(Calendar.WEEK_OF_MONTH,0);
  weekFirst_calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
  weekFirst_date=weekFirst_calendar.getTime();
  weekFirst_time=formatter_1.format(weekFirst_date);
  StringBuffer weekFirst_str=new StringBuffer().append(weekFirst_time).append("  00:00:00");
  weekFirst_time=weekFirst_str.toString();
  prev_time.setText(weekFirst_time);
  
  weekLast_calendar.set(weekFirst_calendar.DAY_OF_MONTH,weekFirst_calendar.get(weekFirst_calendar.DAY_OF_MONTH)+7);  
  weekLast_date=weekLast_calendar.getTime();
  weekLast_time=formatter_1.format(weekLast_date);
  StringBuffer weekLast_str=new StringBuffer().append(weekLast_time).append("  00:00:00");
  weekLast_time=weekLast_str.toString();
  next_time.setText(weekLast_time);

二、以周为单位变化

1、向前推一周

week_cal_1.set(Calendar.DAY_OF_MONTH,week_cal_1.get(Calendar.DAY_OF_MONTH)-7);
   week_date_1=week_cal_1.getTime();
   week_time_1=formatter_1.format(week_date_1);
   StringBuffer str_weekFirst=new StringBuffer().append(week_time_1).append("  00:00:00");
   week_time_1=str_weekFirst.toString();
   text1.setText(week_time_1);
   
   week_cal_2.set(Calendar.DAY_OF_MONTH,week_cal_2.get(Calendar.DAY_OF_MONTH)-7);
   week_date_2=week_cal_2.getTime();
   week_time_2=formatter_1.format(week_date_2);
   StringBuffer str_weekLast=new StringBuffer().append(week_time_2).append("  00:00:00");
   week_time_2=str_weekLast.toString();
   text2.setText(week_time_2);

2、向后推一周

week_cal_1.set(Calendar.DAY_OF_MONTH,week_cal_1.get(Calendar.DAY_OF_MONTH)+7);
   week_date_1=week_cal_1.getTime();
   week_time_1=formatter_1.format(week_date_1);
   StringBuffer str_weekFirst=new StringBuffer().append(week_time_1).append("  00:00:00");
   week_time_1=str_weekFirst.toString();
   text1.setText(week_time_1);
   
   week_cal_2.set(Calendar.DAY_OF_MONTH,week_cal_2.get(Calendar.DAY_OF_MONTH)+7);
   week_date_2=week_cal_2.getTime();
   week_time_2=formatter_1.format(week_date_2);
   StringBuffer str_weekLast=new StringBuffer().append(week_time_2).append("  00:00:00");
   week_time_2=str_weekLast.toString();
   text2.setText(week_time_2);

Java--以周作为时间变化

标签:

原文地址:http://www.cnblogs.com/Hblog/p/5504554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!