1.new Data()
SimpleDateFormat simpleFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String datastring=si1.format(new Date()); //把获取的时间转换为date格式 Date insertDate=simpleFormat.parse(datastring);
免费视频教程推荐:java学习视频
2.system获取
long current=System.currentTimeMillis();//当前时间毫秒数
3.日期类
Calendar rightNow = Calendar.getInstance(); // 子类对象 // 获取年 int year = rightNow.get(Calendar.YEAR); // 获取月 int month = rightNow.get(Calendar.MONTH); // 获取日 int date = rightNow.get(Calendar.DATE); // 获取几点 int hour = rightNow.get(Calendar.HOUR_OF_DAY); // 获取上午下午 int moa = rightNow.get(Calendar.AM_PM); if (moa == 1) { System.out.println("下午"); } else { System.out.println("上午"); } System.out.println(year + "年" + (month + 1) + "月" + date + "日" + hour + "时"); rightNow.add(Calendar.YEAR, 5); rightNow.add(Calendar.DATE, -10); int year1 = rightNow.get(Calendar.YEAR); int date1 = rightNow.get(Calendar.DATE); System.out.println(year1 + "年" + (month + 1) + "月" + date1 + "日" + hour + "时");
相关文章教程推荐:java开发入门
Atas ialah kandungan terperinci java中获取当前时间的几种方式. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!