2014-09-24 205 views
-4

我有串像下面,我需要將其轉換爲日期在Java日期對象的字符串到日期在java中

"Tue Sep 30 00:00:00 GMT+05:30 2014" 

這是java Date對象的字符串表示。我得到它作爲一個字符串,我需要解析它像「2014年9月30日」

我想如果我可以得到這個作爲日期對象我可以得到任何格式我想用simpledateformat。但問題是如何從這個字符串

+3

'SimpleDateFormat'有一個'解析()'方法太 – Bohemian 2014-09-24 12:20:45

+2

反對票來自我。我無法想象,即使有一點先前的研究,你也不會發現'parse()'方法。 – 2014-09-24 12:43:30

回答

-1

the java 8 version有效的格式。 ..你會發現更多的條目已經存在於計算器中。

+0

請不要只在您的答案中鏈接到其他答案或問題。這就是評論意見(或標記)。 – 2014-09-24 12:45:28

1

您還可以使用SimpleDateFomrat字符串解析成日期:

String s = "Tue Sep 30 00:00:00 GMT+05:30 2014"; 
SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); 
System.out.println(df.parse(s)); 
0
public static Date convertDate(final String dateValue) { 
    final SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy"); 
    Date date = null; 
    try { 
     date = format.parse(dateValue); 
     return date; 
    } catch (final ParseException e) { 
     LOG.error(e.getMessage(), e); 
     return null; 
    } 
}