Date class and its methods

The code is as follows:

import java. text. SimpleDateFormat; import java. util. Date; Public class datedemo {/ / get the MS value of the current system time public static void main (string [] args) throws exception {long time = system. Currenttimemillis(); system. Out. Println (time); function(); function_1(); function_2(); function_3(); simpledateformat(); parse();}// Get the current system time public static void function() {date = new date(); system. Out. Println (date);}// Gets the system time public static void function of the specified date_ 1(){ Date date=new Date(0); System.out.println(date); } // Public static void function_ 2(){ Date date=new Date(); long time=date.getTime(); System.out.println(date); System.out.println(time); } // Millisecond value to date public static void function_ 3(){ Date date=new Date(); System.out.println(date); date.setTime(1223141543); System.out.println(date); } // Date formatting (user-defined) (date is converted to string) / / the date formatting class java text. DateFormat abstract class, common method, and also abstract method public static void simpledateformat() {simpledateformat SDF = new simpledateformat ("yyyy MM DD HH: mm: SS"); string date = SDF. Format (New date()); system. Out. Println (date);}// Parse the string into a date object public static void parse() throws exception {simpledateformat SDF = new simpledateformat ("yyyy MM DD"); date date = sdf.parse ("1995-5-6"); system.out.println (date);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>