The formatfun of Java base Class library

Source: Internet
Author: User

 packagecom.exjor.webdemo;Importjava.text.SimpleDateFormat;Importjava.util.Date; public classFormatfun {/*** format_string = YYYY-MM-DD hh:mm:ss. SSS*/     public Static FinalString string_format_datetime = "yyyy-mm-dd hh:mm:ss. SSS "; /*** format_string = YYYY-MM-DD*/     public Static FinalString string_format_onlydate = "yyyy-mm-dd"; /*** format_string = Hh:mm:ss*/     public Static FinalString String_format_onlytime = "hh:mm:ss"; /*** format_string = YYYY-MM-DD hh:mm:ss. SSS*/     public Static FinalSimpleDateFormat Sdf_format_datetime =NewSimpleDateFormat (formatfun.string_format_datetime); /*** format_string = YYYY-MM-DD*/     public Static FinalSimpleDateFormat sdf_format_onlydate =NewSimpleDateFormat (formatfun.string_format_onlydate); /*** format_string = Hh:mm:ss*/     public Static FinalSimpleDateFormat Sdf_format_onlytime =NewSimpleDateFormat (formatfun.string_format_onlytime); /*** format_string = YYYY-MM-DD hh:mm:ss. SSS*/     public Static Final intFormat_datetime = 0; /*** format_string = YYYY-MM-DD*/     public Static Final intFormat_onlydate = 1; /*** format_string = Hh:mm:ss*/     public Static Final intFormat_onlytime = 2; /*** Format Date Object *@parampDate An object of type java.util.Date, or NULL to return "" *@parampformattype Default 0=format_datetime; 1=format_onlydate; 2=format_onlytime *@return     */     public StaticString format (Date pDate,intPformattype) {String vstring= ""; if(pDate! =NULL) {            Switch(pformattype) { caseformat_datetime:vstring=Sdf_format_datetime.format (pDate);  break;  caseformat_onlydate:vstring=Sdf_format_onlydate.format (pDate);  break;  caseformat_onlytime:vstring=Sdf_format_onlytime.format (pDate);  break; default: vstring=Sdf_format_datetime.format (pDate);  break; }        }        returnvstring; }            /*** Format Date Object as DateTime format *@parampDate An object of type java.util.Date, or NULL to return "" *@return     */     public StaticString format (Date PDate) {returnformat (pDate, format_datetime); }        }

The formatfun of Java base Class library

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.