java 获取(格式化)日期格式

// 参考: https://www.cnblogs.com/blog5277/p/6407463.html
public
class DateTest { // 支持时分秒 private static String LocalDateTimeTest(){ LocalDateTime date = LocalDateTime.now(); String res = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); return res; } // 不支持时分秒 private static String LocalDateTest(){ LocalDate date = LocalDate.now(); String res = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); return res; } // 时间戳 private static long getTimestamp(){ return Timestamp.valueOf(LocalDateTimeTest()).getTime(); } public static void main (String[] args) { System.out.println(LocalDateTimeTest()); System.out.println(LocalDateTest()); System.out.println(getTimestamp(LocalDateTest())); } }

 

posted @ 2018-09-21 10:54  lvlin241  阅读(1161)  评论(0编辑  收藏  举报