Java 程序以 ISO_WEEK_DATE 格式设置 LocalDateTime
首先,设置日期
LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 9, 10, 20);
现在,使用 ISO_WEEK_DATE 格式设置日期时间的格式
String str = dateTime.format(DateTimeFormatter.ISO_WEEK_DATE);
示例
import java.time.LocalDateTime; import java.time.Month; import java.time.format.DateTimeFormatter; public class Demo { public static void main(String[] args) { LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 9, 10, 20); System.out.println("DateTime = "+dateTime); String str = dateTime.format(DateTimeFormatter.ISO_WEEK_DATE); System.out.println("Formatted date = "+str); } }
输出
DateTime = 2019-09-09T10:20 Formatted date = 2019-W37-1
广告