Display date in Java

Source: Internet
Author: User
Tags date now dateformat
Import java. util .*;

Import java. Text .*;

Public class styledemo {

Public static void main (string [] ARGs ){

Date Now = new date ();

Dateformat df = dateformat. getdateinstance ();

Dateformat DF1 = dateformat. getdateinstance (dateformat. Short );

Dateformat df2 = dateformat. getdateinstance (dateformat. Medium );

Dateformat df3 = dateformat. getdateinstance (dateformat. Long );

Dateformat df4 = dateformat. getdateinstance (dateformat. Full );

String S = DF. Format (now );

String S1 = df1.format (now );

String S2 = df2.format (now );

String S3 = df3.format (now );

String S4 = df4.format (now );

System. Out. println ("(default) today is" + S );

System. Out. println ("(short) today is" + S1 );

System. Out. println ("(medium) today is" + S2 );

System. Out. println ("(long) today is" + S3 );

System. Out. println ("(full) today is" + S4 );

}

}

That program output the following:

(Default) Today is Nov 8, 2000

(Short) Today is 11/8/00

(Medium) Today is Nov 8, 2000

(Long) Today is November 8, 2000

(Full) Today is Wednesday, November 8, 2000

Related Article

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.