(Android) Get first day of week

前端 未结 4 1809
长发绾君心
长发绾君心 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 16:03

    Try this:

    // get today and clear time of day

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);
    

    // get start of this week in milliseconds

    cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    System.out.println("Start of this week:       " + cal.getTime());
    System.out.println("... in milliseconds:      " + cal.getTimeInMillis());
    

    Reference :How to get the first day of the current week and month?

    Hope this may help you!

提交回复
热议问题