Here you can find the source of stringToTimestamp(String date)
public static long stringToTimestamp(String date)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static long stringToTimestamp(String date) { long time = -1L; if (date.indexOf(" ") == -1) { try { time = (new SimpleDateFormat("yyyy-MM-dd")).parse(date).getTime() / 1000; } catch (ParseException pe) { }/*from ww w .j a v a2 s. c o m*/ } else { try { time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(date).getTime() / 1000; } catch (ParseException pe) { } } return time; } }