Common methods in Date demo
Import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.date;public class Datedemos {public static void main (string[] args) throws Exception {//Gets the system's current time millisecond value long L = S Ystem.currenttimemillis (); System.out.println (l);//1434811870917//encapsulates the current time and date as an object date d = new Date (); System.out.println (d);//sat June 22:51:10 CST 2015//encapsulates the specified milliseconds as an object date D1 = new Date (l); System.out.println (D1);//sat June 22:51:10 CST 2015/** * Millisecond Value-Date object: *. New Date (Timemillis) by constructing a Date object; * *. You can also set it through SetTime. Because the date object can be used to manipulate the fields (year, month, and so on). * Date Object--Millisecond value: * 1. GetTime method. * because it can be calculated by a specific value. * Format Date Object: * String with Date object and date format. * The Format method in the DateFormat class is used. */system.out.println ("_________________________________________");//Gets the current time value of date D2 = new Date ();// Gets the Date object format DateFormat df = dateformat.getdateinstance (); String dat1= Df.format (D2); System.out.println (DAT1); System.out.println ("_________________________________________ ");//Gets the date of the custom format display df = new SimpleDateFormat (" Yyyy--mm--dd "); String dat2= Df.format (D2); System.out.println (DAT2);/** * Converts a date-formatted string to a Date object using the Prase method in the DateFormat class. */string str1= "June 20, 2015";D ateformat DF1 = dateformat.getdateinstance (dateformat.long);D ate Date = Df1.parse (STR1); SYSTEM.OUT.PRINTLN (date);//sat June 00:00:00 CST 2015}}
To run the program:
A common method of the Dark Horse programmer--java--date Class Demo