Java primary application----formatting---Date and time formatting

Source: Internet
Author: User

Problem Description:

The actual programming process, often to output the date and time, but also the date and time to format the output.

Date and time can be converted to a string object, so date and time strings can be formatted using the format () function in the string class .

Programming Ideas:

1) It is clear that the format () function in the String class has two overloaded forms:

    • public static string format (string format, Object ... args)

Function: Causes the string to be formatted according to the format specified by the parameter, and the new string after formatting uses the local default locale

@param format:String describes the expected formatting by this parameter

@param args:Object can have 0 or more of this type parameter

The type parameter is the variable referenced in the parameter format:String

@return a new string that is formatted as required

    • public static string format (Locale l, string format, Object ... args)

Note: The only difference between this function and the above function is that the function can specify the locale used in the formatting process using the parameter Locale and the above functions can only be used by default in the locale

2) Specify formatin the above function:How theString parameter should be written

    1. Uses special symbols to represent the expected date and time format

The above converters are used for formatting dates and times, and the following conversions can be used for formatting of any parameter type:

      

3) Learn programming to format date and time strings after you have learned the basics above

      

4)

Java primary application----formatting---Date and time formatting

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.