前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。?
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)
?