Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

date - (Android) Get first day of week

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.

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...