(Android) Get first day of week

前端 未结 4 1801
长发绾君心
长发绾君心 2020-12-21 15:05

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 so

4条回答
  •  臣服心动
    2020-12-21 15:53

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

    i hope this will help you

提交回复
热议问题