gpt4 book ai didi

java - 如何获取特定周内特定日期的日期

转载 作者:行者123 更新时间:2023-12-02 03:19:38 25 4
gpt4 key购买 nike

我想获取特定周中特定日期的日期,由周数标识。

这是一个例子:

今天是星期一 (03.10.2016),本周是数字 58。现在我想获取例如的日期这周的星期五。

我在 Android 应用程序中使用 Joda-Time。

当前我正在创建一个 LocalDate。

    // This is the date of today
private LocalDate reportDate = new LocalDate();

// The number of the week is calculated here
int week = Weeks.weeksBetween(startDate.dayOfWeek().withMinimumValue().minusDays(1),
reportDate.dayOfWeek().withMaximumValue().plusDays(1)).getWeeks();

switch(day_of_week) {
case "Monday":
// Get date of this day in current week
break;
case "Tuesday":
// Get date of this day in current week
break;
// ...

最佳答案

您可以使用以下代码来实现所需的天数,

    LocalDateTime yourDate = LocalDateTime.now();
System.out.println(yourDate.getWeekOfWeekyear());
int weekOfyear = yourDate.getWeekOfWeekyear();
//Fetch Week Start Date for Given Week Number
DateTime weekStartDate = new DateTime().withWeekOfWeekyear(weekOfyear);
System.out.println(weekStartDate.toString());
//Fetch Specific Days for given week
DateTime wedDateTime = weekStartDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);

我希望这能回答您的问题。

关于java - 如何获取特定周内特定日期的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39816774/

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