前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。
Date date=new Date();DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String time=format.format(date);不同的方法介绍如下:1、通过Date类来获取当前时间。Date day=new Date()SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")System.out.println(df.format(day))2、通过System类中的currentTimeMillis方法来获取当前时间。SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(df.format(System.currentTimeMillis()))3、通过Calendar类来获取当前时间。Calendar c = Calendar.getInstance();//可以对每个时间域单独修改int year = c.get(Calendar.YEAR)int month = c.get(Calendar.MONTH)int date = c.get(Calendar.DATE)int hour = c.get(Calendar.HOUR_OF_DAY)
int minute = c.get(Calendar.MINUTE)int second = c.get(Calendar.SECOND)System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second)4、通过Date类来获取当前时间。Date date = new Date()String year = String.format("%tY", date)String month = String.format("%tB", date)String day = String.format("%te", date)System.out.println("今天是:"+year+"-"+month+"-"+day)