WORK AROUND
(1) Temporarily replace all "-"s in the pattern and strings to be parsed with another delimiter, like "/". The test case given in the Description can be modified to:
import java.text.*;
import java.util.*;
public class Test {
public static void main(String[] args) {
String s = "2002-12,83.567";
System.out.println("DATE 0: " + s);
String pattern = "yyyy'-'mm','ss'.'SSS";
SimpleDateFormat sdf;
Date date = null;
Locale.setDefault(new Locale("ar", "EG"));
sdf = new SimpleDateFormat(pattern.replace("-", "/")); // modified
try {
date = sdf.parse(s.replace("-", "/")); // modified
System.out.println("DATE 1: " + date + " --> " + date.getTime());
} catch (ParseException pe) {
System.out.println("CAUGHT " + pe + ", errorOffset = " +
pe.getErrorOffset());
pe.printStackTrace();
}
}
}
This one produces:
DATE 0: 2002-12,83.567
DATE 1: Tue Jan 01 00:13:23 UTC 2002 --> 1009844003567
(2) When creating a SimpleDateFormat, specify Locale.ENGLISH (or Locale.ROOT in JDK 6) explicitly if the format pattern doesn't involve any Arabic strings (e.g., month names).
import java.text.*;
import java.util.*;
public class Test2 {
public static void main(String[] args) {
String s = "2002-12,83.567";
System.out.println("DATE 0: " + s);
String pattern = "yyyy'-'mm','ss'.'SSS";
SimpleDateFormat sdf;
Date date = null;
Locale.setDefault(new Locale("ar", "EG"));
sdf = new SimpleDateFormat(pattern, Locale.ROOT); // modified
try {
date = sdf.parse(s);
System.out.println("DATE 1: " + date + " --> " + date.getTime());
} catch (ParseException pe) {
System.out.println("CAUGHT " + pe + ", errorOffset = " +
pe.getErrorOffset());
pe.printStackTrace();
}
}
}
This one produces the following as well.
DATE 0: 2002-12,83.567
DATE 1: Tue Jan 01 00:13:23 UTC 2002 --> 1009844003567
|
EVALUATION
Name: nl37777 Date: 03/14/2003
Problem exists in all of 1.1.8, 1.2.2, 1.3.1, 1.4, 1.4.1.
======================================================================
|