【问题标题】:How to round time to the nearest previous quarter hour in Groovy?如何将时间舍入到 Groovy 中最接近的前一刻钟?
【发布时间】:2023-01-15 14:33:04
【问题描述】:

我想要在 Groovy 中到最接近的前一刻钟的时间

例子 : 当前日期:2023-01-15T06:15:51 预期输出(日期时间四舍五入为上一季度):2023-01-15T06:15:00

【问题讨论】:

    标签: groovy


    【解决方案1】:

    导入 java.time.LocalDateTime 导入 java.time.temporal.ChronoUnit

    LocalDateTime CurrentDTM = LocalDateTime.now() println(CurrentDTM)

    LocalDateTime lastQuarter = CurrentDTM.truncatedTo(ChronoUnit.HOURS) .plusMinutes(15 * ((CurrentDTM.getMinute() / 15).intValue())) println(lastQuarter)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      • 2020-02-07
      • 2011-01-29
      • 2016-02-26
      • 1970-01-01
      • 2015-11-27
      相关资源
      最近更新 更多