String now = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
其中的LocalDateTime为java8新增的类,
1、LocalDateTime.now():获取系统当前时间。
2、LocalDateTime.of(intyear,intmonth,intdayOfMonth,inthour,intminute,int second) 按指定日期和时间创建LocalDateTime对象。
3、getYear():返回日期中的年份。
4、getMonth():返回日期中的月份。
5、getDayOfMonth():返回月份中的日。
6、getHour():返回小时。
7、getMinute():返回分钟。
8、getSecond():返回秒。