gpt4 book ai didi

android - Android 中本周开始和结束的日期

转载 作者:太空狗 更新时间:2023-10-29 15:30:17 24 4
gpt4 key购买 nike

我需要在 Android 中找到本周的开始和结束日期。

示例

today: Oct 12 2011 -> result: Oct 10 2011 - Oct 16 2011

today: Oct 1 2001 -> result: Sep 26 2011 - Oct 2 2011

today: Dec 30 2011 -> result: Dec 24 2001 - Jan 1 2011

使用 c.get(Calendar.WEEK_OF_YEAR); 我可以获得周数但如何获得开始和结束日期?我在这里找到了指向 MonthDisplayHelper 的答案,但是如何使用它呢?

谢谢!

最佳答案

使用了这个语法并且有效

    Calendar c1 = Calendar.getInstance();

//first day of week
c1.set(Calendar.DAY_OF_WEEK, 1);

int year1 = c1.get(Calendar.YEAR);
int month1 = c1.get(Calendar.MONTH)+1;
int day1 = c1.get(Calendar.DAY_OF_MONTH);

//last day of week
c1.set(Calendar.DAY_OF_WEEK, 7);

int year7 = c1.get(Calendar.YEAR);
int month7 = c1.get(Calendar.MONTH)+1;
int day7 = c1.get(Calendar.DAY_OF_MONTH);

关于android - Android 中本周开始和结束的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7742618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com