Вопрос

For example, there is a string line 0106201395810 (or 31052013155754), which fits the format of new SimpleDateFormat ("ddMMyyyyHmmss"), ie in the first case, 1 June 2013, 9 hours 58 minutes 10 seconds. Variant with to_date ('0106201395810 ',' DDMMYYYYHH24MISS ') is not suitable because it involves two characters in HH24.

Это было полезно?

Решение

You could try reassembling the string along these lines to have a zero in the right place- and use the DDMMYYYYHH24MISS format

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')

Though I must say, this is ugly, and probably has "less than optimal" performance... I'd much rather change the Java side format, as this format is clearly not a standard one. Individualism can be good at times - this is clearly not the case. This will just cause pain in the long term...

Другие советы

I am not quite sure about your specific need to use ddMMyyyyHmmss ; myself will be using HH for a 24hrs date format

Java

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  
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top