Code 1:
Get the current date using the date class
Public class mydate {public static void main (string [] ARGs) {date mydatestring = new date (); // instantiate the date object system. out. println ("current system date" + mydatestring); // output date }}
:
Code 2:
Obtain the current date using the calender class
Public class mydate02 {public static void main (string [] ARGs) {calendar = NULL; // declare a Calendar Object calendar = new gregoriancalendar (); // instantiate system by subclass. out. println ("year:" + calendar. get (calendar. year); // obtain the year system. out. println ("month:" + (calendar. get (calendar. month) + 1); // Add 1system to the month. out. println ("Date:" + calendar. get (calendar. day_of_month); // use day_of_monthsystem.out.println ("Hour" + calendar. get (calendar. hour_of_day); // use hour_of_daysystem.out.println ("Minutes" + calendar. get (calendar. minute); // minute system. out. println ("seconds" + calendar. get (calendar. second); // second system. out. println ("millisecond" + calendar. get (calendar. millisecond); // millisecond }}
:
Code 3:
Obtain the current date using the dateformat class
Public class mydate03 {public static void main (string [] ARGs) {dateformat DF1 = NULL; // declare dateformat object dateformat df2 = NULL; DF1 = dateformat. getdateinstance (); // get date df2 = dateformat. getdatetimeinstance (); // obtain the date and time system. out. println ("Date:" + df1.format (new date (); // format the date system. out. println ("datetime:" + df2.format (new date ()));}}
:
Code 4:
Set the date format based on code 3:
Public class mydate04 {public static void main (string [] ARGs) {dateformat DF1 = NULL; // declare dateformat object dateformat df2 = NULL; DF1 = dateformat. getdateinstance (dateformat. year_field, new locale ("ZH", "ch"); // get the date and set the date style df2 = dateformat. getdatetimeinstance (dateformat. year_field, dateformat. era_field, new locale ("ZH", "ch"); // obtain the date and time, and set the date display format and time display format system. out. println ("Date:" + df1.format (new date (); // format the date system. out. println ("datetime:" + df2.format (new date ()));}}
:
Not complete...