(Android) 获取一周的第一天 [英] (Android) Get first day of week

查看:50
本文介绍了(Android) 获取一周的第一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们知道一周中的某个日期时,如何获得一周的第一天?

How to get first day of week, when we know one of the date in the week?

我知道当前月份、当前年份和当前星期几.那么,有没有办法知道本周的第一天.

I know the current month , the current year and the current date of week. Then, are there some way to know the first day of the current week.

谢谢.

推荐答案

你好,如果你需要获取当前一周的第一天星期一"

hello if you need to get the first day of the current week "monday"

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH,  Calendar.MONDAY-calendar.get(Calendar.DAY_OF_WEEK));
  Log.w(TAG, "first day of week" + calendar.getTime());

2 如果您需要 20-12-2016 一周的第一天

2 if you need the first day of the week for 20-12-2016

Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 20);
        calendar.set(Calendar.MONTH,Calendar.DECEMBER);
        calendar.set(Calendar.YEAR,2016);
        calendar.add(Calendar.DAY_OF_MONTH,Calendar.MONDAY - calendar.get(Calendar.DAY_OF_WEEK));
    Log.w(TAG,"first day of week:"+calendar.getTime());

希望对你有帮助

这篇关于(Android) 获取一周的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆