Java Date Gets the implementation of the seconds and minutes of the month and day
Package com.util;
Import Java.text.DateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
public class Test {public void gettimebydate () {Date date = new Date ();
DateFormat df1 = Dateformat.getdateinstance ();//date format, accurate to day System.out.println (Df1.format (date));
DateFormat DF2 = Dateformat.getdatetimeinstance ();//Can be accurate to time-seconds System.out.println (Df2.format (date));
DateFormat df3 = Dateformat.gettimeinstance ();//Only show time seconds System.out.println (Df3.format (date)); DateFormat df4 = dateformat.getdatetimeinstance (dateformat.full,dateformat.full);
Display date, week, last afternoon, time (accurate to second) System.out.println (Df4.format (date)); DateFormat df5 = dateformat.getdatetimeinstance (Dateformat.long,dateformat.long);
Display date, last afternoon, time (accurate to second) System.out.println (Df5.format (date)); DateFormat Df6 = dateformat.getdatetimeinstance (Dateformat.short,dateformat.short);
Display date, Upper afternoon, time (exact to minute) System.out.println (Df6.format (date)); DateFormat df7 = dateformat.getdatetimeinstance (dateformat.medIum,dateformat.medium);
Displays the date, time (exact to minute) System.out.println (Df7.format (date));
public void Gettimebycalendar () {Calendar cal = Calendar.getinstance (); int year = Cal.get (calendar.year);//Get years int month=cal.get (calendar.month);//Get month int day=cal.get (calendar.date); Take the day int hour=cal.get (calendar.hour),//hour int minute=cal.get (calendar.minute);//min. int Second=cal.get (calendar.se COND);//sec int weekofyear = Cal.get (Calendar.day_of_week);///The day of the Week System.out.println ("Now the time is: A.D." +year+ "Year" +month+ "month"
+day+ "Day" +hour+ "when" +minute+ "minutes" +second+ "Seconds Week" +weekofyear);
public static void Main (string[] args) {test t=new test ();
T.gettimebydate ();
System.out.println ("****************************");
T.gettimebycalendar (); }
}
Get day, if greater than 16 then + 2 months, otherwise + 1 months, output 7 months
public static void Main (string[] as) throws Exception {
int J;
Calendar cc = Calendar.getinstance ();
int myyear = Cc.get (calendar.year);
int mymonth = Cc.get (calendar.month);
J=cc.get (calendar.date) >16?3:2;
Cc.set (Calendar.month, mymonth+j);
System.out.println (myyear+ "-" +cc.get (CC). MONTH));
for (int i=0;i<7;i++) {
cc.add (cc. MONTH, 1);
int mm = Cc.get (CC. MONTH);
int mmm=mm==0?12:mm;
System.out.println (myyear+ "-" +mmm);
}
}
The above Java date to obtain the date and time of the month and a minute to achieve the method is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.