Here you can find the source of toDate(String timeStamp)
public static Date toDate(String timeStamp)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static Date toDate(String timeStamp) { try {/*from ww w .j av a 2s . c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'SSS"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(timeStamp); } catch (ParseException e) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(timeStamp); } catch (ParseException e1) { e1.printStackTrace(); return new Date(0L); } } } }