Java programming notes 4 format strings

Source: Internet
Author: User

Other classes are used to format strings, rather than the string class itself, such as the representation of dates and currencies.

 

Format Date: 

 

DateClass:

  

Constructor:

Date() Allocate a date object and initialize it to indicate the time (accurate to milliseconds) it is allocated ).

Date(Long date) allocates a date object and initializes this object to indicate the specified number of milliseconds since the standard reference time (EPOCH), that is, January 1, 1970 00:00:00 GMT.


Other methods:

 

DateformatClass: 

 

 

Public abstract classDateformatExtends format

Constructor:

Dateformat() Create a New dateformat.

 

Other methods:

Public final stringFormat(Date) format a date as a date/time string.

 

Public static final dateformatGetdateinstance(INT style) Get the date formatter, which has a given format style in the default language environment

 

Public static final dateformatGettimeinstance() Get the time formatter, which has the Default Formatting style in the default language environment

 

Public static final dateformatGetdatetimeinstance() Get the date/time formatter, which has the Default Formatting style in the default language environment

 

Format a number:

NumberformatClass:

Public abstract classNumberformatExtends format

 

Static numberformat

Getcurrencyinstance()
Returns the currency format of the current default language environment.

Static numberformat

Getcurrencyinstance(Locale inlocale)
Returns the currency format of the specified language environment.

Static numberformat

Getpercentinstance(Locale inlocale)
Returns the percentage format of the specified language environment.

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.