Java里的日期和时间学习
Date date = new Date();//yyyy-mm-dd hh:mm:ss[.fffffffff] SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.0"); System.out.println("现在的日期时间是:" + sdf.format(date));; Calendar c = Calendar.getInstance(); // c.setTime(date); int second = c.get(Calendar.SECOND); System.out.println("现在的小时是"+second); int second2 = c.get(c.SECOND); System.out.println(second2); //拿到当前系统时间 System.out.println(System.currentTimeMillis()); //时区 Calendar japan = new GregorianCalendar(TimeZone.getTimeZone("Japan")); System.out.println(japan.get(Calendar.HOUR_OF_DAY)); //打印时区ID for (String timezone : TimeZone.getAvailableIDs()) { System.out.println("时区的id " + timezone); }