您的位置:首页 > 移动开发 > Android开发

根据当前系统时间设置日期(周一至日)

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));

设置成功之后即能显示
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android string 日期