In "Java" about System.currenttimemillis () thought (click the Open link) has been described, if the use of System.currenttimemillis () to take out the current period. In Java, you can actually use the Calendar class to get the current date. Only its cumbersome, to take out the current year, month, day, time, minutes, seconds to splice it together.
The following code:
Import Java.util.calendar;import Java.util.gregoriancalendar;public class Calendartest {public static void main (String [] args) {Calendar calendar=calendar.getinstance (); System.out.println ("Now Is:" +calendar.get (gregoriancalendar.year) + "year" + (Calendar.get (gregoriancalendar.month) +1) + " Month "+calendar.get (gregoriancalendar.day_of_month) +" Day "+calendar.get (gregoriancalendar.hour) +" Time "+calendar.get ( Gregoriancalendar.minute) + "min" +calendar.get (Gregoriancalendar.second) + "SEC");}}
The results of the operation are as follows:
As you can see, the result of the run corresponds to the current time.
In the above code, the Calendar.get (gregoriancalendar.xx) is used to remove the month-date and minute-by-day, different from the previous calendar.get (CALENDAR.XXX), which prevents eclipse from warning. If written as Calendar.get (CALENDAR.XXX), the following hint appears in eclipse: calendar.xxx should is accessed in a static.
Also, note that taking the current month, you must check out the result of +1, which is the correct current month. Otherwise, the result is 1 less than the current month.
The current day is Calendar.get (gregoriancalendar.day_of_month), not Calendar.get (Gregoriancalendar.day).
"Java" uses the Calendar class to get the current date