Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...