Problems with date display in Java

Source: Internet
Author: User
Tags date format date now dateformat string
Problem | show 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) is" + s);
System.out.println ("(short) are" + S1);
System.out.println ("(MEDIUM) is" + S2);
System.out.println ("(LONG) is" + S3);
System.out.println ("(full) are" + S4);
}
}


The 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.