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 ~