Java Format Time Sample _java

Source: Internet
Author: User

The format of the implementation date, the class needs to be used: Java.text.DateFormat

DateFormat does not have a constructor that can be used directly, typically using dateformate subclasses---java.text.SimpleDateFormat to complete the construct.

Public SimpleDateFormat (String pattern)

Test code

Copy Code code as follows:

Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
public class Dateformattest
{

public static void Main (string[] args)//Note: String do not write strings
{
DateFormat df = new SimpleDateFormat ("yyyy mm month DD Day Hh:mm:ss");
Date currenttime = new Date ();
String CURRENTTIMEDF = Df.format (currenttime);
System.out.println ("Current time is:" +CURRENTTIMEDF);
}
}

SimpleDateFormat has the following characteristics

1. Accept the corresponding format string and format the parts in date to display. Wherein, the YYYY represents the year, the MM represents the month, DD represents the day, and the HH represents the hour, mm represents the minute, and the SS represents the second

2, in the format string, in addition to the representative meaning of the part, the other parts appear as is.

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.