Here you can find the source of getTimeX(String dateStr)
public static long getTimeX(String dateStr)
//package com.java2s; //License from project: Artistic License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long getTimeX(String dateStr) { long time = 0; time = getDate(dateStr).getTime() / 1000; return time; }// w w w . j a v a2 s. c o m public static long getTimeX(String dateStr, String format) { long time = 0; time = getDate(dateStr, format).getTime() / 1000; return time; } public static long getTimeX(Date date) { long time = 0; time = date.getTime() / 1000; return time; } public static long getTime(String dateStr, String format) { long time = -1; Date date = getDate(dateStr, format); if (date != null) { time = getDate(dateStr, format).getTime(); } return time; } public static long getTime(String dateStr) { long time = -1; String format = "yyyy-MM-dd HH:mm:ss"; Date date = getDate(dateStr, format); if (date != null) { time = getDate(dateStr, format).getTime(); } return time; } public static Date getDate(String dateStr, String formatString) { Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat(formatString); date = sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); } return date; } public static Date getDate(String dateStr) { return getDate(dateStr, "yyyy-MM-dd HH:mm:ss"); } }