1 package com.ob;
2
3 import java.text.ParseException;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
6 import java.util.Date;
7
8 public class DateTest {
9
10 public static void main(String[] args) throws ParseException {
11 Calendar now = Calendar.getInstance();
12 System.out.println("年: " + now.get(Calendar.YEAR));
13 System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
14 System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
15 System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
16 System.out.println("分: " + now.get(Calendar.MINUTE));
17 System.out.println("秒: " + now.get(Calendar.SECOND));
18 System.out.println("当前时间毫秒数:" + now.getTimeInMillis());
19 System.out.println(now.getTime());
20
21
Java获取当前时间的年月日方法
最新推荐文章于 2024-07-16 04:46:13 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)