import java.text.DateFormat ; import java.util.Date ; public class DateDemo03{ public static void main(String args[]){ DF1 DateFormat = null ; // declare a DateFormat DateFormat DF2 = null ; // declare a DateFormat DF1 = DateFormat.getDateInstance (); // get a DateFormat object date DF2 = DateFormat.getDateTimeInstance (); // get the date and time DateFormat Object System.out.println ( "dATE:" + df1.format ( new new a date ())); // by date format System.out.println ( "DATETIME:" + df2.format ( new new a date ())) ; // formatted according to the date and time } };
import java.text.DateFormat ; import java.util.Date ; import java.util.Locale ; public class DateDemo04{ public static void main(String args[]){ DF1 DateFormat = null ; // declare a DateFormat DateFormat DF2 = null ; // declare a DateFormat DF1 = DateFormat.getDateInstance (DateFormat.YEAR_FIELD, new new Locale ( "ZH", "the CN")); // get a DateFormat object date = DateFormat.getDateTimeInstance DF2 (DateFormat.YEAR_FIELD, DateFormat.ERA_FIELD, new new Locale ( "ZH", "the CN")); // get the date and time the object DateFormat System.out.println ( "dATE:" + df1.format ( new new a date ())); // by date format System.out.println ( "DATETIME:" + df2 .format(newDATE ())); // formatted according to the date and time } };
import java.text.* ; import java.util.* ; public class DateDemo05{ public static void main(String args[]){ StrDate String = "2008-10-19 10:. 11: 30.345" ; // prepare first a template, extracted from digital date string String PAT1 = "the MM-dd-YYYY HH: mm: ss.SSS" ; // prepare the second template, the number after the date of the extracted data to the specified format String pat2 = "yyyy Year mM month dd day when HH mm ss a SSS millisecond" ; SDF-I the SimpleDateFormat = new new the SimpleDateFormat (PAT1); // instantiate a template objects the SimpleDateFormat SDF2 = new new the SimpleDateFormat (PAT2); // instantiate a template objects a Date D = null ; the try { D = sdf1.parse (strDate); // given date string extracted from } the catch (Exception E) { // If the format string supplied error, exception handling is performed e.printStackTrace (); // print exception information } System.out.println (sdf2.format (D)); // the date becomes the new format } };