Java版本:1.8开始
import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; /***/
Created by Frank
public class CurrentDatetime {
public static void main(String[] args) {
LocalDate dNow = LocalDate.now();
System.out.println(dNow);
LocalTime tNow = LocalTime.now();
System.out.println(tNow);
LocalDateTime now = LocalDateTime.now();
System.out.println(now);DateTimeFormatter df </span>= DateTimeFormatter.ofPattern("yyyy/MM/dd"<span style="color: #000000;">); System.out.println(df.format(LocalDateTime.now())); System.out.println(LocalDate.parse(</span>"2016/11/28"<span style="color: #000000;">, df)); DateTimeFormatter nTZ </span>= DateTimeFormatter.ofPattern("d MMMM, yyyy h:mm a"<span style="color: #000000;">); System.out.println(ZonedDateTime.now().format(nTZ));
}
}
运行输出:
2016-11-28 17:11:34.131 2016-11-28T17:11:34.131 2016/11/28 2016-11-28 28 十一月, 2016 5:11 下午
原文地址:https://www.cnblogs.com/frankyou/p/6110393.html