技术社区
回复列表
-
0092020-02-14
1. public class DateTimeTest {
2. public static void main(String[] args) {
3. Calendar cal = Calendar.getInstance();
4. System.out.println(cal.get(Calendar.YEAR));
5. System.out.println(cal.get(Calendar.MONTH)); // 0 - 11
6. System.out.println(cal.get(Calendar.DATE));
7. System.out.println(cal.get(Calendar.HOUR_OF_DAY));
8. System.out.println(cal.get(Calendar.MINUTE));
9. System.out.println(cal.get(Calendar.SECOND));
10. // Java 8 11. LocalDateTime dt = LocalDateTime.now();
12. System.out.println(dt.getYear());
13. System.out.println(dt.getMonthValue()); // 1 - 12
14. System.out.println(dt.getDayOfMonth());
15. System.out.println(dt.getHour());
16. System.out.println(dt.getMinute());
17. System.out.println(dt.getSecond());
18. }