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

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  阅读(1174)  评论(0)    收藏  举报