您可以使用以下代码来实现您的需求:\n\ngroovy\nimport java.time.LocalDateTime\nimport java.time.LocalTime\n\nLocalDateTime now = LocalDateTime.now()\n\nLocalDateTime targetDateTime = LocalDateTime.of(now.getYear(), 1, 1, 0, 0, 0, 0)\n\nif (now.getDayOfMonth() <= 2 && now.toLocalTime().isBefore(LocalTime.MIDNIGHT)) {\n targetDateTime = targetDateTime.withMonth(now.getMonthValue())\n}\n\nprintln targetDateTime\n\n\n这段代码将获取当前时间,然后创建一个目标时间,即每年的1月1日00:00:00.000。然后,如果当前时间的日期小于等于2并且时间小于午夜,将目标时间的月份设置为当前月份。最后,打印目标时间。

Groovy: 获取每月2号00:00:00.000时间并调整到本月1号

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

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