根据当前系统时间设置日期(周一至日)
2017-02-06 14:06
295 查看
写一个方法如下:
public String getOurSelWeek(int sel) {
Date date = null;
String[] weekDaysName = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
SimpleDateFormat df = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.roll(Calendar.DAY_OF_YEAR, sel);
String str = df.format(calendar.getTime());
try {
date = df.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
calendar.setTime(date);
int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
return weekDaysName[intWeek];
}
然后在需要展示的布局处 调用该方法
tv_week.setText(xxxActivity.this.getOurSelWeek(1));
设置成功之后即能显示
public String getOurSelWeek(int sel) {
Date date = null;
String[] weekDaysName = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
SimpleDateFormat df = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.roll(Calendar.DAY_OF_YEAR, sel);
String str = df.format(calendar.getTime());
try {
date = df.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
calendar.setTime(date);
int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
return weekDaysName[intWeek];
}
然后在需要展示的布局处 调用该方法
tv_week.setText(xxxActivity.this.getOurSelWeek(1));
设置成功之后即能显示
相关文章推荐
- android 日期格式处理 ,获取当前系统时间并设置格式为--年--月--日
- 根据当前系统时间获取工作日日期
- Android根据系统设置获得对应格式的当前日期字符串
- 根据当前日期,获得本周的周一及周日日期即本周的开始时间和结束时间
- asp.net 根据当前时间获取本周、上周、下周的周一、周日日期
- java另一种获取当前系统的时间与日期
- Linux下设置系统日期和时间
- 取得系统当前日期和时间
- 读取、设置系统时间日期
- WinCE.NET中设置系统日期时间
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)[转]
- 设置PDA系统日期时间
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- 根据当前日期获取本周起止时间
- VC++得到当前系统时间日期 GetSystemTime()
- java中获取当前系统时间,日期并格式化输出
- 根据当前日期获取本周起止时间
- 系统日期时间格式设置
- WinCE.NET中设置系统日期时间