`

Java 8 获取当前日期

    博客分类:
  • Java
 
阅读更多

原创转载请注明出处:https://agilestyle.iteye.com/blog/2435106

 

Code Demo

public static String getCurrentDateTime() {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    return LocalDateTime.now().format(formatter);
}

public static String getCurrentDateTime(String format) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
    return LocalDateTime.now().format(formatter);
}

 

Test

System.out.println(getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
System.out.println(getCurrentDateTime("yyMMddHHmmss"));
System.out.println(getCurrentDateTime("yyyyMMdd"));
System.out.println(getCurrentDateTime("HHmmss"));
System.out.println(getCurrentDateTime());

 

Console Output


 

 

 

  • 大小: 16.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics