Here you can find the source of parseDateTimeFromString(String datetime)
public static Date parseDateTimeFromString(String datetime)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { private static final ThreadLocal<SimpleDateFormat> RFC_822_DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() { @Override/*w w w .j a va2 s.c o m*/ protected SimpleDateFormat initialValue() { SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format; } }; private static final ThreadLocal<SimpleDateFormat> RFC_850_DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { SimpleDateFormat format = new SimpleDateFormat("EEEE, dd-MMM-yy HH:mm:ss z", Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format; } }; private static final ThreadLocal<SimpleDateFormat> ANSI_DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format; } }; public static Date parseDateTimeFromString(String datetime) { Date date = tryToParse(datetime, RFC_822_DATE_FORMAT.get()); if (date == null) { date = tryToParse(datetime, RFC_850_DATE_FORMAT.get()); } if (date == null) { date = tryToParse(datetime, ANSI_DATE_FORMAT.get()); } return date; } private static Date tryToParse(String datetime, SimpleDateFormat format) { try { return format.parse(datetime); } catch (ParseException e) { return null; } } }