Java程序将LocalTimeDate格式化为BASIC_ISO_DATE格式
首先,设置日期:
LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);
现在,将日期时间格式化为BASIC_ISO_DATE格式:
String str = dateTime.format(DateTimeFormatter.BASIC_ISO_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, 6, 20, 10); System.out.println("DateTime = "+dateTime); String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE); System.out.println("Formatted date = "+str); } }
输出结果
DateTime = 2019-09-06T20:10 Formatted date = 20190906