Here you can find the source of dateformat(String dateTime)
public static Date dateformat(String dateTime) throws ParseException
//package com.java2s; //License from project: LGPL import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date dateformat(String dateTime) throws ParseException { SimpleDateFormat formatter = null; //String dateTime = "2002-02-02T22:22:22Z"; //String dateTime = "2002-02-02"; int dot = dateTime.indexOf('.'); int col = dateTime.indexOf(':'); if (col > 0) { if (dot > 0) { formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); }// ww w.j av a 2 s . com } else { formatter = new SimpleDateFormat("yyyy-MM-dd"); } //formatter.setTimeZone(TimeZone.getTimeZone("GMT")); Date dt = formatter.parse(dateTime); return dt; } }