【问题标题】:JodaTime - first day of next weekendJodaTime - 下周末的第一天
【发布时间】:2014-05-19 20:25:37
【问题描述】:

在JodaTime中,可以计算下周末的第一天吗?例如,现在是 19.05.2014(星期一),下周末的第一天是星期六 24.05.2014。

【问题讨论】:

    标签: jodatime


    【解决方案1】:
    // algorithm valid for ISO-8601-definition of a week
    // (every week starting on Monday)
    
    LocalDate date = LocalDate.now(); // in system timezone
    
    // move after current weekend
    if (date.getDayOfWeek() >= 6) {
      date = date.plusDays(2);
    }
    
    // move to next Saturday (your definition of first day of a weekend)
    date = date.withDayOfWeek(6);
    System.out.println(date); // 2014-05-24 (if today is 2014-05-19)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-01
      • 2020-03-30
      • 2012-10-08
      • 2015-02-13
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多