java如何使用代码获取当前的年,月,日,小时,分钟,秒,毫秒呢?
下文笔者讲述使用java代码获取年,月,日,小时,分钟,秒,毫秒的方法分享,如下所示
实现思路:
使用LocalDateTime对象即可获取当前时刻的一些信息
例:
LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
int hour = now.getHour();
int minute = now.getMinute();
int second = now.getSecond();
int millis = now.get(ChronoField.MILLI_OF_SECOND);
System.out.printf("%d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, millis);
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


