【发布时间】:2015-11-02 08:18:48
【问题描述】:
我正在从 oracle 表中获取结果,并且想要设置特定的日期格式,即 dd-MMM-yyyy hh:mm。
我不知道日期存储在哪个位置或列位置。
我尝试检查列类型并更改日期,但此操作非常耗时。
如何转换这个日期?
下面是我的代码:
if((colType.get(num).equalsIgnoreCase("DATE")))
{
String getDate = rs.getString(colName.get(num));
String convertedDate = "";
if(getDate!=null||!getDate.isEmpty())
{
DateFormat originalFormat = new SimpleDateFormat("MM/dd/yyyy H:m:s");
SimpleDateFormat targetFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
Date date = originalFormat.parse(getDate);
convertedDate = targetFormat.format(date);
bw.write(convertedDate);
bw.write("|");
}
}
【问题讨论】: