2013-08-01 79 views
-2

我正在从数据库表中的时间戳这种格式03.03.03 14:29:34.000 (yy.mm.dd HH24:MI:SS)时间戳需要格式化

如下图所示,现在我需要将其转换成这种格式20130509 06:00,请指教如何实现的日期这种格式

+4

首先,你应该从数据库*被取它作为一个日期*而不是一种特定的文本格式。然后,在Stack Overflow上有很多关于格式化日期和时间的问题。你有什么尝试,出了什么问题? –

+0

你的时间戳的类型是什么? –

+0

pleae让我知道格式为日期设置日期格式如20130509 06:00 –

回答

0

可以以这种方式使用SampleDateFormat:

Date myDate = new Date(); // The date you post 
String S = new SimpleDateFormat("yyyyMMdd HH:mm").format(myDate); 

我不明白20130509如果05是一个月或一天。我认为05作为月份和09为天

2

您可以使用java.text.SimpleDateFormat中:

final String strSrcDate = "09.05.13 14:29:34.000"; 
final DateFormat srcFormat = new SimpleDateFormat(
     "dd.MM.yy HH:mm:ss.SSS"); 
final Date date = srcFormat.parse(strSrcDate); 
final DateFormat destFormat = new SimpleDateFormat("yyyyMMdd HH:mm"); 
final String strDestDate = destFormat.format(date); 
System.out.println(strSrcDate); 
System.out.println(strDestDate);