你可以使用LocalDateTimeTemporalAdjusters来获取每月2号的时间。下面是一个示例代码:

import java.time.LocalDateTime
import java.time.temporal.TemporalAdjusters

// 获取当前日期时间
LocalDateTime now = LocalDateTime.now()

// 获取每月2号的时间
LocalDateTime date = now.with(TemporalAdjusters.firstDayOfMonth()).withDayOfMonth(2).withHour(0).withMinute(0).withSecond(0)

println(date)

这段代码首先获取当前的日期时间(LocalDateTime.now()),然后使用TemporalAdjusters来获取本月的第一天(with(TemporalAdjusters.firstDayOfMonth())),然后再设置日期为2号(withDayOfMonth(2)),最后将时间设置为00:00:00(withHour(0).withMinute(0).withSecond(0))。

输出的结果将是每月2号的00:00:00的时间


原文地址: http://www.cveoy.top/t/topic/icLN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录