1

例如,有一个字符串行0106201395810(或31052013155754),它符合格式new SimpleDateFormat ("ddMMyyyyHmmss"),即在第一种情况下,2013 年 6 月 1 日,9 小时 58 分 10 秒。变体 withto_date ('0106201395810 ',' DDMMYYYYHH24MISS ')不适合,因为它涉及HH24中的两个字符。

4

2 回答 2

2

您可以尝试按照这些行重新组装字符串,以便在正确的位置有一个零 - 并使用DDMMYYYYHH24MISS格式

to_date(
 case length(input)
  when 14 THEN -- the length is OK: this has 2 digits at the hour
     input
  when 13 THEN -- length is one short, have to add one '0'
     substr(input,0,8) || '0' || substr(input, 9)
  END,
'DDMMYYYYHH24MISS')

虽然我必须说,这很丑陋,并且可能具有“不太理想”的性能......我宁愿更改 Java 端格式,因为这种格式显然不是标准格式。个人主义有时会很好——显然不是这样。这只会导致长期的痛苦......

于 2013-09-25T07:53:42.863 回答
1

我不太确定您是否需要使用 ddMMyyyyHmmss ;我自己将使用 HH 作为 24 小时日期格式

爪哇

String s1 = "0106201395810";
Date d1 = (new SimpleDateFormat("ddMMyyyyHmmss")).parse(s1);
String s2 = (new SimpleDateFormat("ddMMyyyyHHmmss")).format(d1);
System.out.println("s2 "+s2);

SQL

select to_date ('01062013095810', 'DDMMYYYYHH24MISS' ) from dual  
于 2013-09-25T09:04:06.250 回答