Java date format

Source: Internet
Author: User

1 Date Format example:

Public static final string date_format_1 = "m/D/YYYY ";
Public static final string date_format_2 = "mm/DD/YYYY ";
Public static final string date_format_3 = "m/D/YYYY hh: mm: ss ";
Public static final string date_format_4 = "yyyy-mm-dd ";
Public static final string date_format_5 = "eeeee, mmm. dd ";
Public static final string date_format_long = "Mmmmm DD, yyyy eeeee ";
Public static final string date_format_short = "Mmm DD, yyyy eee ";
Public static final string date_format_hour_twenty_four = "mm/DD/YYYY hh: mm: SS ";
Public static final string date_format_hour_twelve = "mm/DD/YYYY hh: mm: ss ";
Public static final string date_format_coupon = "yyyy-mm-dd't'hh: mm: SS ";
// #8601
Public static final string date_format_pv_event = "yyyymmdd. hhmmss. ssszz ";

2. Format a date type

/**
* Format date
*
* @ Param Format
* @ Param date
* @ Return formatted date string
*/
Public static string formatdate (string format, date ){
Return dateformat. Format (format, date). tostring ();
}

3. Format a date string type

/**
*
* @ Param date
* @ Param formatin
* @ Param formatout
* @ Return
*/
Public static string changedateformate (string date, string formatin, string formatout ){

Simpledateformat formats = new simpledateformat (formatin, locale. US );
Simpledateformat outformat = new simpledateformat (formatout, locale. US );

Try {
Date mdate = partition. parse (date );
Return outformat. Format (mdate );
} Catch (parseexception e ){
E. printstacktrace ();
}

Return date;
}

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.