Java Data Type How to - Parse date from excel file in u2013 Unicode character instead of a normal dash








Question

We would like to know how to parse date from excel file in u2013 Unicode character instead of a normal dash.

Answer

import java.text.SimpleDateFormat;
import java.util.Date;
//from w w w .jav  a 2  s.co m
public class Main {
  public static void main(String[] args) throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String trouble = "18?11?2003";
    String goodOne = "18-11-2003";
    Date date = simpleDateFormat.parse(goodOne);
    System.out.println(date);
    date = simpleDateFormat.parse(trouble);
    System.out.println(date);
    System.out.println(String.format("\\u%04x", (int) trouble.charAt(2)));
    System.out.println(String.format("\\u%04x", (int) goodOne.charAt(2)));

  }
}

The code above generates the following result.