java8获取当前时间并格式化

String now  = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());

其中的LocalDateTime为java8新增的类,

1LocalDateTime.now():获取系统当前时间。

2LocalDateTime.of(intyear,intmonth,intdayOfMonth,inthour,intminute,int second) 按指定日期和时间创建LocalDateTime对象。

3getYear():返回日期中的年份。

4getMonth():返回日期中的月份。

5getDayOfMonth():返回月份中的日。

6getHour():返回小时。

7getMinute():返回分钟。

8getSecond():返回秒。


猜你喜欢

转载自blog.csdn.net/qq_27507937/article/details/75384835
今日推荐