Android tips: price display (¥358,179,682) and date operations (three months forward from the current day)

Source: Internet
Author: User

1. Price display problems such as price display (¥358,179,682) are often encountered in application development.

Private string getstring (string Str)
{
If (Str. Equals ("") | STR = "")
{
Return "";
}
Else
{
Locale. setdefault (locale. China); // in Chinese Language
Numberformat currencyformat = numberformat. getcurrencyinstance ();
String [] arr = currencyformat. Format (long. parselong (STR ))
. Replace (".", ""). Split ("");
Return arr [0];
}
}

2. Get the current date and time three months ago (note that other methods may encounter errors of 4.31 or 2.29)
/**
* @ Description get the current date and time three months ago
*/
Public void getdate ()
{
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd ");

Calendar Cal = calendar. getinstance ();
Date = Cal. gettime ();
Mdate = SDF. Format (date );
Cal. Add (calendar. Month,-3 );
Date fdate = Cal. gettime ();
Mfdate = SDF. Format (fdate );
}

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.