在Java中格式化日期所需的帮助

问题描述:

嗨我有以下日期作为字符串格式。在Java中格式化日期所需的帮助

输入

2010-04-20 05:34:58.0 

输出我要像

20, Apr 2010 

字符串谁能告诉我该怎么办呢?

试试这个:

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); 
DateFormat outputFormat = new SimpleDateFormat("dd, MMM yyyy"); 

Date yourDate = inputFormat.parse("2010-04-20 05:34:58.0"); 
String formattedDate = outputFormat.format(yourDate); 
+0

如何构建yourDate。我以字符串格式 – bragboy 2010-04-20 14:05:30

+2

有一件事情,这个模式(和我的,下面):这个月将打印一个点,这取决于语言环境。法文:“四月” – 2010-04-20 14:08:21

你可能想试试这个:

SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); 
Date date = inFormat.parse("2010-04-20 05:34:58.0"); 

SimpleDateFormat outFormat = new SimpleDateFormat("dd, MMM yyyy"); 
System.out.println(outFormat.format(date));