Java时间类、时间转换类的使用
public static void main(String[] args) {
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalDateTime localDate1 = LocalDateTime.now();//年月日时分秒
LocalDate localDate2 = LocalDate.now();//年月日
LocalTime localDate3 = LocalTime.now();//时分秒
System.out.println("年月日时分秒:"+dateTimeFormatter1.format(localDate1));
System.out.println("年月日:"+dateTimeFormatter2.format(localDate2));
System.out.println("时分秒:"+dateTimeFormatter3.format(localDate3));
}
网友评论