Import Java.text.*;import java.util.*;class Test2 {public static void main (string[] args) {System.out.println ( System.currenttimemillis ());//The method is to return the current computer time, the time expression format is the current computer time and GMT time (GMT) January 1, 1970 0:0 0 seconds the number of milliseconds. Long Currenttime=system.currenttimemillis (); SimpleDateFormat formatter = new SimpleDateFormat ("yyyy years mm DD Day hh mm min ss sec"); SimpleDateFormat formatter1=new SimpleDateFormat ("D-day of the Year in the year of the first W week January the first W week in the day K time Z time zone"); G-year marker//y//M/D Day//h in the morning or afternoon (1~12)//h in one day (0~23)//M min/s S/S//E Week//d in the first day of the year//F January the first few weeks/w mid-week//W January the first few weeks//a morning/afternoon marker//K when in the day (1~24)//k in the morning or afternoon (0~11)//Z Time zone date date=new date ( ); System.out.println (Formatter.format (date)); Calendar cal = Calendar.getinstance ();//Calendar provides a class method getinstance to obtain a generic object of this type. The getinstance method of the calendar returns a Calendar object that has been initialized by the current date and time: Date date1 = Cal.gettime (); System.out.println (Formatter1.format (date1)); String osname = System.getproperty ("OS.Name "); String user = System.getproperty ("User.Name"); SYSTEM.OUT.PRINTLN ("Current operating system is:" + osname); System.out.println ("Current user is:" + user); }}
Results:
1440157503152233 Day 34th Monday Month 4th week in one day 11 o'clock GMT time zone The current operating system is: Windows NT (unknown) The current user is: Administrator
Java Date Class Summary