Java obtains the summary of the current time method, and java obtains the current time
The simplest way to get the current time is as follows:
Method 1:
Import java. util. calendar; public class DateTime {public static void main (String [] args) {Calendar Ar c = Calendar ar. getInstance (); System. out. println ("current time:"); System. out. println (c. get (Calendar. YEAR) + "YEAR" + (c. get (Calendar. MONTH) + 1) + "MONTH" + c. get (Calendar. DATE) + "day"); System. out. println (c. get (Calendar. HOUR) + "point" + c. get (Calendar. MINUTE) + "points" + c. get (Calendar. SECOND) + "seconds"); System. out. println ("Today is the day of the year:" + c. get (Calendar. DAY_OF_YEAR) + "day"); System. out. println ("Today is the day of the year:" + c. get (Calendar. WEEK_OF_YEAR) + "weeks ");}}
Method 2:
Import java. util. date; import java. text. simpleDateFormat; public class NowString {public static void main (String [] args) {SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss "); // set the date format System. out. println (df. format (new Date (); // new Date () is used to obtain the current system time }}
Method 3:
Import java. util. date; import java. util. calendar; import java. text. simpleDateFormat; public class TestDate {public static void main (String [] args) {Date now = new Date (); SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd HH: mm: ss "); // you can easily modify the Date Format String hehe = dateFormat. format (now); System. out. println (hehe); Calendar c = Calendar. getInstance (); // You can individually modify int year = c for each time field. 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 );}}