Java Data Type How to - Parse a String to Date 'Sun Nov 10 10:00:00 CET 2013'








Question

We would like to know how to parse a String to Date 'Sun Nov 10 10:00:00 CET 2013'.

Answer

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
// w ww.  jav  a2 s .c o m
public class Main {
  public static void main(String[] args) {
    String input = "Sun Nov 10 10:00:00 CET 2013";
    SimpleDateFormat parserSDF = new SimpleDateFormat(
        "EEE MMM d HH:mm:ss ZZZ yyyy");
    System.out.println(parserSDF.parse(input, new ParsePosition(0)));
  }
}