JAVA Date Class

Source: Internet
Author: User

Package com.feicuiedu.test;

import Java.text.DateFormat;
import Java.util.Calendar;
import java.util.Date;


Public class Date {
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 cent seconds
System.out.println (Df2.format (date));
DateFormat df3 = dateformat.gettimeinstance ();//Only shows the seconds
System.out.println (Df3.format (date));
DateFormat df4 = dateformat.getdatetimeinstance (dateformat.full,dateformat.full);//display date, week, afternoon, time (accurate to seconds)
System.out.println (Df4.format (date));
DateFormat df5 = dateformat.getdatetimeinstance (Dateformat.long,dateformat.long);//display date, last afternoon, time (accurate to seconds)
System.out.println (Df5.format (date));
DateFormat Df6 = dateformat.getdatetimeinstance (dateformat.short,dateformat.short);//display date, last afternoon, time (accurate to minute)
System.out.println (Df6.format (date));
DateFormat df7 = dateformat.getdatetimeinstance (dateformat.medium,dateformat.medium);//display date, time (accurate 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);//Acquisition Day
int Hour=cal.get (calendar.hour);//hour
int Minute=cal.get (calendar.minute);//min
int Second=cal.get (calendar.second);//sec
int weekofyear = Cal.get (Calendar.day_of_week);//day of the week
System.out.println ("The Present time is: A.D." +year+ "Year" +month+ "month" +day+ "Day" +hour+ "when" +minute+ "cent" +second+ "Seconds Week" +weekofyear ";
}
Public static void Main (string[] args) {
Date T=new date ();
t.gettimebydate ();
System.out.println ("****************************");
T.gettimebycalendar ();
}
}

JAVA Date Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.