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 = DateTimeFormatter.ofPattern("yyyy/MM/dd"); System.out.println(df.format(LocalDateTime.now())); System.out.println(LocalDate.parse("2016/11/28", df)); DateTimeFormatter nTZ = DateTimeFormatter.ofPattern("d MMMM, yyyy h:mm a"); 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 下午
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/15864.html