Android examples for java.util:Date Convert
Format string in yyyy-MM-dd HH:mm:ss format to long
import java.text.SimpleDateFormat; public class Main { public static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static boolean isNotBlank(String str) { return str != null && !str.trim().equals(""); }/* w ww . j a v a 2s .c o m*/ public static long convert2long(String date) { try { if (isNotBlank(date)) { SimpleDateFormat sf = new SimpleDateFormat(TIME_FORMAT); return sf.parse(date).getTime(); } } catch (Exception e) { e.printStackTrace(); } return 0l; } }