Here you can find the source of dateTime(String s)
public static Date dateTime(String s)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.TimeZone; import static java.util.Arrays.asList; public class Main { public static final TimeZone UTC = TimeZone.getTimeZone("UTC"); public static Date dateTime(String s) { List<DateFormat> formats = asList(dateTimeFormat("kk:mm dd/MM/yyyy", UTC), dateTimeFormat("kk:mm:ss dd/MM/yyyy", UTC), dateTimeFormat("kk:mm:ss.SSS dd/MM/yyyy", UTC), dateTimeFormat("E MMM dd kk:mm:ss Z yyyy", UTC)); for (DateFormat format : formats) { try { return format.parse(s); } catch (ParseException ignored) { }//from ww w .j av a 2s .co m } throw new RuntimeException("Failed to parse string as dateTime: " + s); } public static DateFormat dateTimeFormat(String pattern, TimeZone timeZone) { SimpleDateFormat format = new SimpleDateFormat(pattern); format.setTimeZone(timeZone); return format; } }