Us time format-date conversion in complex formats uses the date. parse ("complex format") method.

Source: Internet
Author: User
Tags dateformat

Use this method

    long time = Date.parse("Sun Feb 26 10:31:58 +0800 2012");    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");    Date d = new Date(time);    System.out.println(sdf.format(d));

Us time format

// G era flag text ad
// Year 1996, Y; 96
// Month July; Jul; 07 in m years
// Week number 27 in W years
// Week number 2 in the month of W
// Number of days in d 189
// D Number of days in the month 10
// Number 2 of the week in month F
// The number of days in the E week text Tuesday; TUE
// A AM/PM mark text pm
// H hour in a day (0-23) number 0
// K the hour in a day (1-24) Number 24
// Hours in k am/PM (0-11) number 0
// H am/PM hours (1-12) Number 12
// The number of minutes in M hours is 30
// Number of seconds in seconds 55
// S number of milliseconds number 978
// Z Time Zone General Time Zone Pacific Standard Time; PST; GMT-08: 00
// Z Time Zone RFC 822 Time Zone-0800

Dateformat df = dateformat. getdatetimeinstance (dateformat. Full, dateformat. Full, locale. China );

Simpledateformat SDF = new simpledateformat ("eee Mmm dd hh: mm: SS Zzzzz YYYY", locale. US );
Date D;
Try {

D = SDF. parse ("Sun Feb 26 10:31:58 + 0800 2012 ");
Long date = D. gettime ();
} Catch (parseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}

In the preceding statement, if the red parameter is not added, an error is returned during conversion ~

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.